mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-17 04:30:57 +01:00
add test code
This commit is contained in:
2
go.mod
2
go.mod
@@ -13,7 +13,7 @@ require (
|
|||||||
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895 // indirect
|
github.com/ebitengine/gomobile v0.0.0-20240518074828-e86332849895 // indirect
|
||||||
github.com/ebitengine/hideconsole v1.0.0 // indirect
|
github.com/ebitengine/hideconsole v1.0.0 // indirect
|
||||||
github.com/ebitengine/purego v0.7.0 // indirect
|
github.com/ebitengine/purego v0.7.0 // indirect
|
||||||
github.com/ebitenui/ebitenui v0.5.8-0.20240608175527-424f62327b21 // indirect
|
github.com/ebitenui/ebitenui v0.5.8-0.20240608230235-27496c28f409 // indirect
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||||
github.com/jezek/xgb v1.1.1 // indirect
|
github.com/jezek/xgb v1.1.1 // indirect
|
||||||
github.com/tinne26/etxt v0.0.8 // indirect
|
github.com/tinne26/etxt v0.0.8 // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -10,6 +10,8 @@ github.com/ebitenui/ebitenui v0.5.6 h1:qyJRU5j+lQo1lamxB48IBwMxMfz1xNb5iWUayCtA0
|
|||||||
github.com/ebitenui/ebitenui v0.5.6/go.mod h1:I0rVbTOUi7gWKTPet2gzbvhOdkHp5pJXMM6c6b3dRoE=
|
github.com/ebitenui/ebitenui v0.5.6/go.mod h1:I0rVbTOUi7gWKTPet2gzbvhOdkHp5pJXMM6c6b3dRoE=
|
||||||
github.com/ebitenui/ebitenui v0.5.8-0.20240608175527-424f62327b21 h1:dElhYGyf+FYY+makAndUQNOSDwFSFYyFWziPwQrPObY=
|
github.com/ebitenui/ebitenui v0.5.8-0.20240608175527-424f62327b21 h1:dElhYGyf+FYY+makAndUQNOSDwFSFYyFWziPwQrPObY=
|
||||||
github.com/ebitenui/ebitenui v0.5.8-0.20240608175527-424f62327b21/go.mod h1:I0rVbTOUi7gWKTPet2gzbvhOdkHp5pJXMM6c6b3dRoE=
|
github.com/ebitenui/ebitenui v0.5.8-0.20240608175527-424f62327b21/go.mod h1:I0rVbTOUi7gWKTPet2gzbvhOdkHp5pJXMM6c6b3dRoE=
|
||||||
|
github.com/ebitenui/ebitenui v0.5.8-0.20240608230235-27496c28f409 h1:wsPobs+O3ZmZvhtNtmnMkaB1FRM7tuZ60P0/jegRQGg=
|
||||||
|
github.com/ebitenui/ebitenui v0.5.8-0.20240608230235-27496c28f409/go.mod h1:I0rVbTOUi7gWKTPet2gzbvhOdkHp5pJXMM6c6b3dRoE=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
github.com/hajimehoshi/ebiten/v2 v2.7.4 h1:X+heODRQ3Ie9F9QFjm24gEZqQd5FSfR9XuT2XfHwgf8=
|
github.com/hajimehoshi/ebiten/v2 v2.7.4 h1:X+heODRQ3Ie9F9QFjm24gEZqQd5FSfR9XuT2XfHwgf8=
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func NewGame(config *Config, startscene SceneName) *Game {
|
|||||||
game.Scenes[Menu] = NewMenuScene(game, config)
|
game.Scenes[Menu] = NewMenuScene(game, config)
|
||||||
game.Scenes[Options] = NewOptionsScene(game, config)
|
game.Scenes[Options] = NewOptionsScene(game, config)
|
||||||
game.Scenes[Keybindings] = NewKeybindingsScene(game, config)
|
game.Scenes[Keybindings] = NewKeybindingsScene(game, config)
|
||||||
|
game.Scenes[Toolbar] = NewToolbarScene(game, config)
|
||||||
|
|
||||||
// setup environment
|
// setup environment
|
||||||
ebiten.SetWindowSize(game.ScreenWidth, game.ScreenHeight)
|
ebiten.SetWindowSize(game.ScreenWidth, game.ScreenHeight)
|
||||||
@@ -67,6 +68,7 @@ func (game *Game) Update() error {
|
|||||||
|
|
||||||
func (game *Game) Draw(screen *ebiten.Image) {
|
func (game *Game) Draw(screen *ebiten.Image) {
|
||||||
// first draw primary scene[s], although there are only 1
|
// first draw primary scene[s], although there are only 1
|
||||||
|
skip := false
|
||||||
for current, scene := range game.Scenes {
|
for current, scene := range game.Scenes {
|
||||||
if scene.IsPrimary() {
|
if scene.IsPrimary() {
|
||||||
// primary scenes always draw
|
// primary scenes always draw
|
||||||
@@ -74,11 +76,15 @@ func (game *Game) Draw(screen *ebiten.Image) {
|
|||||||
|
|
||||||
if current == game.CurrentScene {
|
if current == game.CurrentScene {
|
||||||
// avoid to redraw it in the next step
|
// avoid to redraw it in the next step
|
||||||
return
|
skip = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if skip {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
scene := game.GetCurrentScene()
|
scene := game.GetCurrentScene()
|
||||||
scene.Draw(screen)
|
scene.Draw(screen)
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/play.go
12
src/play.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
uiinput "github.com/ebitenui/ebitenui/input"
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||||
@@ -424,11 +425,12 @@ func (scene *ScenePlay) Update() error {
|
|||||||
return quit
|
return quit
|
||||||
}
|
}
|
||||||
|
|
||||||
scene.CheckInput()
|
if !uiinput.UIActive {
|
||||||
scene.CheckDrawingInput()
|
scene.CheckInput()
|
||||||
scene.CheckDraggingInput()
|
scene.CheckDrawingInput()
|
||||||
scene.CheckMarkInput()
|
scene.CheckDraggingInput()
|
||||||
|
scene.CheckMarkInput()
|
||||||
|
}
|
||||||
if !scene.Config.Paused || scene.RunOneStep {
|
if !scene.Config.Paused || scene.RunOneStep {
|
||||||
scene.UpdateCells()
|
scene.UpdateCells()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,5 @@ const (
|
|||||||
Play // actual playing happens here
|
Play // actual playing happens here
|
||||||
Options
|
Options
|
||||||
Keybindings
|
Keybindings
|
||||||
|
Toolbar
|
||||||
)
|
)
|
||||||
|
|||||||
94
src/toolbar.go
Normal file
94
src/toolbar.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image/color"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/ebitenui/ebitenui"
|
||||||
|
"github.com/ebitenui/ebitenui/widget"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SceneToolbar struct {
|
||||||
|
Game *Game
|
||||||
|
Config *Config
|
||||||
|
Next SceneName
|
||||||
|
Prev SceneName
|
||||||
|
Whoami SceneName
|
||||||
|
Ui *ebitenui.UI
|
||||||
|
FontColor color.RGBA
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewToolbarScene(game *Game, config *Config) Scene {
|
||||||
|
scene := &SceneToolbar{
|
||||||
|
Whoami: Toolbar,
|
||||||
|
Game: game,
|
||||||
|
Next: Toolbar,
|
||||||
|
Config: config,
|
||||||
|
FontColor: color.RGBA{255, 30, 30, 0xff},
|
||||||
|
}
|
||||||
|
|
||||||
|
scene.Init()
|
||||||
|
|
||||||
|
return scene
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) GetNext() SceneName {
|
||||||
|
return scene.Next
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) SetPrevious(prev SceneName) {
|
||||||
|
scene.Prev = prev
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) ResetNext() {
|
||||||
|
scene.Next = scene.Whoami
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) SetNext(next SceneName) {
|
||||||
|
scene.Next = next
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) IsPrimary() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) Update() error {
|
||||||
|
scene.Ui.Update()
|
||||||
|
|
||||||
|
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) || inpututil.IsKeyJustPressed(ebiten.KeyQ) {
|
||||||
|
scene.SetNext(Play)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) Draw(screen *ebiten.Image) {
|
||||||
|
scene.Ui.Draw(screen)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) SetInitialValue(w *widget.LabeledCheckbox, value bool) {
|
||||||
|
if value {
|
||||||
|
w.SetState(
|
||||||
|
widget.WidgetChecked,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scene *SceneToolbar) Init() {
|
||||||
|
rowContainer := NewTopRowContainer("Toolbar")
|
||||||
|
|
||||||
|
cancel := NewMenuButton("Close",
|
||||||
|
func(args *widget.ButtonClickedEventArgs) {
|
||||||
|
os.Exit(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
rowContainer.AddChild(cancel)
|
||||||
|
|
||||||
|
scene.Ui = &ebitenui.UI{
|
||||||
|
Container: rowContainer.Container(),
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -215,6 +215,37 @@ func (container *RowContainer) Container() *widget.Container {
|
|||||||
return container.Root
|
return container.Root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setup a top level toolbar container
|
||||||
|
func NewTopRowContainer(title string) *RowContainer {
|
||||||
|
buttonImageHover := image.NewNineSlice(Assets["button-9slice3"], [3]int{3, 3, 3}, [3]int{3, 3, 3})
|
||||||
|
|
||||||
|
uiContainer := widget.NewContainer(
|
||||||
|
widget.ContainerOpts.Layout(widget.NewAnchorLayout()),
|
||||||
|
)
|
||||||
|
|
||||||
|
rowContainer := widget.NewContainer(
|
||||||
|
widget.ContainerOpts.WidgetOpts(
|
||||||
|
widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{
|
||||||
|
HorizontalPosition: widget.AnchorLayoutPositionStart,
|
||||||
|
VerticalPosition: widget.AnchorLayoutPositionStart,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
widget.ContainerOpts.Layout(widget.NewRowLayout(
|
||||||
|
widget.RowLayoutOpts.Direction(widget.DirectionVertical),
|
||||||
|
widget.RowLayoutOpts.Padding(widget.NewInsetsSimple(8)),
|
||||||
|
widget.RowLayoutOpts.Spacing(0),
|
||||||
|
)),
|
||||||
|
widget.ContainerOpts.BackgroundImage(buttonImageHover),
|
||||||
|
)
|
||||||
|
|
||||||
|
uiContainer.AddChild(rowContainer)
|
||||||
|
|
||||||
|
return &RowContainer{
|
||||||
|
Root: uiContainer,
|
||||||
|
Row: rowContainer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set arg to false if no background needed
|
// set arg to false if no background needed
|
||||||
func NewRowContainer(title string) *RowContainer {
|
func NewRowContainer(title string) *RowContainer {
|
||||||
buttonImageHover := image.NewNineSlice(Assets["button-9slice3"], [3]int{3, 3, 3}, [3]int{3, 3, 3})
|
buttonImageHover := image.NewNineSlice(Assets["button-9slice3"], [3]int{3, 3, 3}, [3]int{3, 3, 3})
|
||||||
|
|||||||
Reference in New Issue
Block a user