Skip to content

Commit

Permalink
fix: fix tutorial for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Aug 30, 2024
1 parent 54179ae commit 1c4ecf2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 11 additions & 2 deletions game/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ func NewSession(options ...func(s *Session)) *Session {
session.SetOnLuaError(nil)

session.luaState, session.luaDocs = SessionAdapter(session)
session.resources = NewResourcesManager(session.luaState, session.luaDocs, session.log)
session.resources.MarkBaseGame()

for i := range options {
if options[i] == nil {
Expand All @@ -165,8 +167,6 @@ func NewSession(options ...func(s *Session)) *Session {
options[i](session)
}

session.resources = NewResourcesManager(session.luaState, session.luaDocs, session.log)
session.resources.MarkBaseGame()
session.loadMods(session.loadedMods)

session.log.Println("Session started!")
Expand Down Expand Up @@ -212,6 +212,15 @@ func WithMods(mods []string) func(s *Session) {
}
}

// WithLuaString sets the lua code that should be executed.
func WithLuaString(lua string) func(s *Session) {
return func(s *Session) {
if err := s.luaState.DoString(lua); err != nil {
s.logLuaError("WithLuaString", "", err)
}
}
}

// WithSeed sets the seed for the random number generator.
func WithSeed(seed uint64) func(s *Session) {
return func(s *Session) {
Expand Down
5 changes: 2 additions & 3 deletions ui/menus/mainmenu/mainmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -151,7 +150,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case ChoiceTutorial:
audio.Play("btn_menu")

tutorialLua, err := filepath.Abs("./assets/tutorial/tutorial.lua")
tutorialLua, err := fs.ReadFile("./assets/tutorial/tutorial.lua")
if err != nil {
panic(err)
}
Expand All @@ -160,7 +159,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Sequence(
cmd,
root.Push(gameview.New(m, m.zones, game.NewSession(
game.WithMods([]string{tutorialLua}),
game.WithLuaString(string(tutorialLua)),
))),
)
case ChoiceAbout:
Expand Down

0 comments on commit 1c4ecf2

Please sign in to comment.