From cf7caad2dc83539fb58b27e68fe462fc9b9fea17 Mon Sep 17 00:00:00 2001 From: iegod Date: Mon, 21 Aug 2023 08:00:24 -0400 Subject: [PATCH] Refactoring for module packaging. --- main.go => examples/splashmenu/main.go | 7 +- examples/splashmenu/{ => scenes}/menu.go | 0 examples/splashmenu/{ => scenes}/splash.go | 0 go.mod | 2 +- groovy/manager.go | 101 --------------------- groovy/scene.go | 9 -- 6 files changed, 6 insertions(+), 113 deletions(-) rename main.go => examples/splashmenu/main.go (82%) rename examples/splashmenu/{ => scenes}/menu.go (100%) rename examples/splashmenu/{ => scenes}/splash.go (100%) delete mode 100644 groovy/manager.go delete mode 100644 groovy/scene.go diff --git a/main.go b/examples/splashmenu/main.go similarity index 82% rename from main.go rename to examples/splashmenu/main.go index d7ff134..476ce16 100644 --- a/main.go +++ b/examples/splashmenu/main.go @@ -1,9 +1,10 @@ package main import ( + "cosmos/diego/groovy" + splashmenu "cosmos/diego/groovy/examples/splashmenu/scenes" + "fmt" - "groovy/examples/splashmenu" - "groovy/groovy" "log" "github.com/hajimehoshi/ebiten/v2" @@ -35,4 +36,6 @@ func loadScenes(m *groovy.Manager) { //sets current scene to the splash menu m.SetCurrentScene(0) + + m.SetDimensions(groovy.Area{Width: 1280, Height: 720}) } diff --git a/examples/splashmenu/menu.go b/examples/splashmenu/scenes/menu.go similarity index 100% rename from examples/splashmenu/menu.go rename to examples/splashmenu/scenes/menu.go diff --git a/examples/splashmenu/splash.go b/examples/splashmenu/scenes/splash.go similarity index 100% rename from examples/splashmenu/splash.go rename to examples/splashmenu/scenes/splash.go diff --git a/go.mod b/go.mod index da80db2..72b62eb 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module groovy +module cosmos/diego/groovy go 1.21.0 diff --git a/groovy/manager.go b/groovy/manager.go deleted file mode 100644 index 7cb7d57..0000000 --- a/groovy/manager.go +++ /dev/null @@ -1,101 +0,0 @@ -package groovy - -import ( - "os" - - "github.com/hajimehoshi/ebiten/v2" -) - -const ( - defaultWidth = 1024 - defaultHeight = 768 -) - -type Area struct { - Width int - Height int -} - -type GameInfo struct { - Name string - Version string - Dimension Area -} - -type Manager struct { - Info GameInfo - currentScene Scene - currentSceneId int - scenes []Scene -} - -// can be used to create default manager instance -func NewManager() Manager { - return Manager{ - Info: GameInfo{ - Name: "groovy", - Version: "1.0", - Dimension: Area{ - Width: defaultWidth, - Height: defaultHeight}, - }, - currentSceneId: 0, - } -} - -// ebitengine update proxy -// manages scene transition and exists, then calls scene's update method -func (m *Manager) Update() error { - if m.currentScene == nil { - return nil - } - - m.CheckTransitions() - m.CheckExit() - - //call the current scene's update method - return m.currentScene.Update() - -} - -// check for exit condition -func (m *Manager) CheckExit() { - if m.currentSceneId >= len(m.scenes) { - os.Exit(0) - } -} - -// check for scene completion and if reached, set up next scene (if available) -func (m *Manager) CheckTransitions() { - if m.currentScene.Completed() { - m.currentSceneId++ - if m.currentSceneId < len(m.scenes) { - m.currentScene = m.scenes[m.currentSceneId] - } - } -} - -// calls current scene's draw method if the currentscene is valid -func (m *Manager) Draw(screen *ebiten.Image) { - if m.currentScene != nil { - m.currentScene.Draw(screen) - } -} - -// ebitengine proxy for layout -func (m *Manager) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) { - return m.Info.Dimension.Width, m.Info.Dimension.Height -} - -// appends scene to the managed scenes -func (m *Manager) AddScene(s Scene) { - m.scenes = append(m.scenes, s) -} - -// sets the current scene, based on sceneindex -func (m *Manager) SetCurrentScene(sceneId int) { - if sceneId >= 0 && sceneId < len(m.scenes) { - m.currentSceneId = sceneId - m.currentScene = m.scenes[m.currentSceneId] - } -} diff --git a/groovy/scene.go b/groovy/scene.go deleted file mode 100644 index 1044db7..0000000 --- a/groovy/scene.go +++ /dev/null @@ -1,9 +0,0 @@ -package groovy - -import "github.com/hajimehoshi/ebiten/v2" - -type Scene interface { - Update() error - Draw(screen *ebiten.Image) - Completed() bool -}