前三个点位所有功能已调通
This commit is contained in:
24
internal/routes/play.go
Normal file
24
internal/routes/play.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"game-driver/internal/routes/play"
|
||||
"game-driver/leaf"
|
||||
)
|
||||
|
||||
func PlayRouter(location string, point int) leaf.HandlerFunc {
|
||||
switch location {
|
||||
case "wushan":
|
||||
return switchPoint(point)
|
||||
default:
|
||||
return play.Default
|
||||
}
|
||||
}
|
||||
|
||||
func switchPoint(point int) leaf.HandlerFunc {
|
||||
switch point {
|
||||
case 3:
|
||||
return play.OnlyVideo
|
||||
default:
|
||||
return play.Default
|
||||
}
|
||||
}
|
||||
19
internal/routes/play/default.go
Normal file
19
internal/routes/play/default.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package play
|
||||
|
||||
import (
|
||||
"game-driver/internal/middleware"
|
||||
"game-driver/internal/schema"
|
||||
"game-driver/leaf"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Default(c *leaf.Context) {
|
||||
payload := leaf.Value[*schema.PlayModal](c, middleware.PayloadJSONKey)
|
||||
|
||||
if w, ok := payload.Game["wait"]; ok {
|
||||
select {
|
||||
case <-c.Done():
|
||||
case <-time.After(time.Duration(w.(int)) * time.Second):
|
||||
}
|
||||
}
|
||||
}
|
||||
17
internal/routes/play/only_video.go
Normal file
17
internal/routes/play/only_video.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package play
|
||||
|
||||
import (
|
||||
"game-driver/internal/middleware"
|
||||
"game-driver/internal/schema"
|
||||
"game-driver/leaf"
|
||||
"game-driver/pkg/utils"
|
||||
"game-driver/pkg/video"
|
||||
)
|
||||
|
||||
func OnlyVideo(c *leaf.Context) {
|
||||
payload := leaf.Value[*schema.PlayModal](c, middleware.PayloadJSONKey)
|
||||
|
||||
if url, ok := payload.Game["video"]; ok {
|
||||
_ = video.Play(c, utils.LinkVideo(url.(string)))
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"game-driver/pkg/audio"
|
||||
"game-driver/pkg/relay"
|
||||
"game-driver/pkg/tts"
|
||||
"game-driver/pkg/utils"
|
||||
"game-driver/pkg/video"
|
||||
"github.com/gopxl/beep/v2/speaker"
|
||||
"log"
|
||||
"sync"
|
||||
@@ -51,26 +53,32 @@ func WaitAction(c *leaf.Context) {
|
||||
switch item.Type {
|
||||
case schema.WaitAudio:
|
||||
// 执行音乐播放
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
wait.Add(1)
|
||||
defer wait.Done()
|
||||
audioAction(c, item, payload.TimeModel)
|
||||
}()
|
||||
case schema.WaitTTS:
|
||||
// 执行TTS播放
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
wait.Add(1)
|
||||
defer wait.Done()
|
||||
ttsAction(c, item, payload.TimeModel)
|
||||
}()
|
||||
case schema.WaitRelay:
|
||||
// 执行继电器供电
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
wait.Add(1)
|
||||
defer wait.Done()
|
||||
relayAction(c, item, payload.TimeModel)
|
||||
}()
|
||||
case schema.WaitVideo:
|
||||
// 执行视频播放
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
defer wait.Done()
|
||||
videoAction(c, item, payload.TimeModel)
|
||||
}()
|
||||
case schema.WaitWeb:
|
||||
default:
|
||||
log.Printf("不支持的类型: %d\n", item.Type)
|
||||
@@ -95,7 +103,7 @@ func audioAction(c *leaf.Context, item schema.WaitItemModel, root schema.TimeMod
|
||||
case <-timerAction(item.Start):
|
||||
{
|
||||
log.Println("开始执行后台任务")
|
||||
data := audio.LinkAudio(item.Data)
|
||||
data := utils.LinkAudio(item.Data)
|
||||
|
||||
ctrl, closer := audio.PlayBgmMP3(data)
|
||||
defer closer()
|
||||
@@ -177,3 +185,33 @@ func relayAction(c *leaf.Context, item schema.WaitItemModel, root schema.TimeMod
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func videoAction(c *leaf.Context, item schema.WaitItemModel, root schema.TimeModel) {
|
||||
if item.Start != 0 && time.Unix(item.Start, 0).Before(time.Unix(root.Start, 0)) {
|
||||
log.Println("开始时间小于根任务开始时间")
|
||||
return
|
||||
}
|
||||
|
||||
if item.End != 0 {
|
||||
cancel := leaf.WithDeadline(c, time.Unix(item.End, 0))
|
||||
defer cancel()
|
||||
}
|
||||
|
||||
select {
|
||||
case <-c.Done():
|
||||
case <-timerAction(item.Start):
|
||||
{
|
||||
for {
|
||||
err := video.Play(c, utils.LinkVideo(item.Data))
|
||||
if err != nil {
|
||||
log.Panicln("视频播放异常: ", err)
|
||||
}
|
||||
select {
|
||||
case <-c.Done():
|
||||
return
|
||||
case <-time.After(time.Duration(item.Interval) * time.Second):
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user