more refact

This commit is contained in:
2026-08-30 23:01:48 +02:00
parent 3890edc946
commit 28b1662195
38 changed files with 353 additions and 663 deletions
+3 -74
View File
@@ -4,42 +4,7 @@ import (
inkwell "git.teletypegames.org/engines/inkwell"
)
func (w *world) Do(a inkwell.Action) {
if a != nil {
w.queue = append(w.queue, a)
}
}
func (w *world) PumpTick(dt float64) {
if w.running == nil {
if len(w.queue) == 0 {
return
}
w.running = w.queue[0].Start()
w.queue = w.queue[1:]
}
ctx := &inkwell.Ctx{
Game: w.G,
DT: dt,
}
if s, ok := w.G.SceneManager.Get(w.G.CurrentScene()); ok {
ctx.Scene = &s
}
if w.running.Tick(ctx) != inkwell.StatusRunning {
w.running = nil
}
}
func (w *world) SceneTitle() string {
s, ok := w.G.SceneManager.Get(w.G.CurrentScene())
if !ok {
return ""
}
if s.Title != "" {
return s.Title
}
return s.Name
}
func (w *world) Do(a inkwell.Action) { w.G.Do(a) }
type fnAction struct{ fn func(*inkwell.Ctx) }
@@ -70,42 +35,6 @@ func SetMode(m Mode) inkwell.Action {
return Fn(func(*inkwell.Ctx) { World.SetMode(m) })
}
func TapeSay(speaker, text string) inkwell.Action {
return &tapeSayAction{
speaker: speaker,
text: text,
}
}
type tapeSayAction struct{ speaker, text string }
func (a *tapeSayAction) Start() inkwell.Runner {
return &tapeSayRunner{
spec: a,
}
}
type tapeSayRunner struct {
spec *tapeSayAction
started bool
elapsed float64
duration float64
}
func (r *tapeSayRunner) Tick(ctx *inkwell.Ctx) inkwell.Status {
if !r.started {
r.started = true
r.duration = 1.2 + float64(len([]rune(r.spec.text)))*0.05
ctx.Game.LogResponse(r.spec.speaker, r.spec.text)
}
r.elapsed += ctx.DT
if r.elapsed >= r.duration {
return inkwell.StatusDone
}
return inkwell.StatusRunning
}
func TapeOffer(line inkwell.Action) inkwell.Action {
return Fn(func(*inkwell.Ctx) {
World.tapeLine = line
@@ -149,11 +78,11 @@ type pausedRunner struct {
func (r *pausedRunner) Tick(ctx *inkwell.Ctx) inkwell.Status {
if !r.started {
r.started = true
World.paused = true
World.SetNote(NotePaused)
}
s := r.inner.Tick(ctx)
if s != inkwell.StatusRunning {
World.paused = false
World.SetNote("")
}
return s
}