From 79be685b156bae63000d5b02f62cfd687b426773 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 14 Mar 2024 02:27:49 +0800 Subject: [PATCH 1/7] getSpriteProto/getSpriteProtoByName --- game.go | 144 ++++++++++++++++++++++++++++++------------------------ sprite.go | 18 +++---- 2 files changed, 90 insertions(+), 72 deletions(-) diff --git a/game.go b/game.go index 4ae3ffa6..f987527a 100644 --- a/game.go +++ b/game.go @@ -24,6 +24,7 @@ import ( "log" "math/rand" "os" + "path/filepath" "reflect" "sync/atomic" "time" @@ -78,8 +79,9 @@ type Game struct { sounds soundMgr turtle turtleCanvas - shapes map[string]Spriter // sprite prototypes - items []Shape // sprites on stage + typs map[string]reflect.Type // map: name => sprite type, for all sprites + sprs map[string]Spriter // map: name => sprite prototype, for loaded sprites + items []Shape // shapes on stage (in Zorder), not only sprites tickMgr tickMgr input inputMgr @@ -100,12 +102,16 @@ type Game struct { sinkMgr eventSinkMgr isLoaded bool + isRunned bool } -type Spriter = Shape +type Spriter interface { + Shape + Main() +} type Gamer interface { - initGame() + initGame(sprites []Spriter) } func (p *Game) getSharedImgs() *sharedImages { @@ -115,23 +121,59 @@ func (p *Game) getSharedImgs() *sharedImages { return p.shared } +func (p *Game) newSpriteAndLoad(name string, tySpr reflect.Type, g reflect.Value) Spriter { + spr := reflect.New(tySpr).Interface().(Spriter) + if err := p.loadSprite(spr, name, g); err != nil { + panic(err) + } + // p.sprs[name] = spr (has been set by loadSprite) + return spr +} + +func (p *Game) getSpriteProto(tySpr reflect.Type, g reflect.Value) Spriter { + name := tySpr.Name() + spr, ok := p.sprs[name] + if !ok { + spr = p.newSpriteAndLoad(name, tySpr, g) + } + return spr +} + +func (p *Game) getSpriteProtoByName(name string, g reflect.Value) Spriter { + spr, ok := p.sprs[name] + if !ok { + tySpr, ok := p.typs[name] + if !ok { + log.Panicf("sprite %s is not defined\n", name) + } + spr = p.newSpriteAndLoad(name, tySpr, g) + } + return spr +} + func (p *Game) reset() { p.sinkMgr.reset() p.input.reset() p.Stop(AllOtherScripts) p.items = nil p.isLoaded = false - p.shapes = make(map[string]Spriter) + p.sprs = make(map[string]Spriter) } -func (p *Game) initGame() { +func (p *Game) initGame(sprites []Spriter) { p.tickMgr.init() p.eventSinks.init(&p.sinkMgr, p) + p.sprs = make(map[string]Spriter) + p.typs = make(map[string]reflect.Type) + for _, spr := range sprites { + tySpr := reflect.TypeOf(spr).Elem() + p.typs[tySpr.Name()] = tySpr + } } // Gopt_Game_Main is required by Go+ compiler as the entry of a .gmx project. -func Gopt_Game_Main(game Gamer) { // TODO(xsw): sprites ...Spriter) { - game.initGame() +func Gopt_Game_Main(game Gamer, sprites ...Spriter) { + game.initGame(sprites) game.(interface{ MainEntry() }).MainEntry() } @@ -149,8 +191,8 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { conf = *gameConf[0] err = loadProjConfig(&proj, fs, conf.Index) } else { - // load Config from index.json - if err = loadProjConfig(&proj, fs, nil); err == nil { + err = loadProjConfig(&proj, fs, nil) + if proj.Run != nil { // load Config from index.json conf = *proj.Run } } @@ -158,6 +200,7 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { panic(err) } + appName := filepath.Base(os.Args[0]) if !conf.DontParseFlags { f := flag.CommandLine verbose := f.Bool("v", false, "print verbose information") @@ -165,7 +208,7 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { help := f.Bool("h", false, "show help information") flag.Parse() if *help { - fmt.Fprintf(os.Stderr, "Usage: %v [-v -f -h]\n", os.Args[0]) + fmt.Fprintf(os.Stderr, "Usage: %v [-v -f -h]\n", appName) flag.PrintDefaults() return } @@ -174,6 +217,9 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { } conf.FullScreen = *fullscreen } + if conf.Title == "" { + conf.Title = appName + " (by Go+ Builder)" + } key := conf.ScreenshotKey if key == "" { @@ -191,9 +237,7 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { if debugLoad { log.Println("==> StartLoad", resource) } - if err := g.startLoad(fs, &conf); err != nil { - panic(err) - } + g.startLoad(fs, &conf) for i, n := 0, v.NumField(); i < n; i++ { name, val := getFieldPtrOrAlloc(v, i) switch fld := val.(type) { @@ -207,6 +251,7 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { if err := g.loadSprite(fld, name, v); err != nil { panic(err) } + // p.sprs[name] = fld (has been set by loadSprite) } } if err := g.endLoad(v, &proj); err != nil { @@ -252,7 +297,7 @@ func getFieldPtrOrAlloc(v reflect.Value, i int) (name string, val interface{}) { typ := tFld.Type word := unsafe.Pointer(vFld.Addr().Pointer()) ret := reflect.NewAt(typ, word).Interface() - if vFld.Kind() == reflect.Ptr && typ.Implements(tyShape) { + if vFld.Kind() == reflect.Ptr && typ.Implements(tySpriter) { obj := reflect.New(typ.Elem()) reflect.ValueOf(ret).Elem().Set(obj) ret = obj.Interface() @@ -290,20 +335,17 @@ func findObjPtr(v reflect.Value, name string, from int) interface{} { return nil } -func (p *Game) startLoad(fs spxfs.Dir, cfg *Config) (err error) { +func (p *Game) startLoad(fs spxfs.Dir, cfg *Config) { var keyDuration int if cfg != nil { keyDuration = cfg.KeyDuration } - p.initGame() p.input.init(p, keyDuration) p.sounds.init(p) - p.shapes = make(map[string]Spriter) p.events = make(chan event, 16) p.fs = fs p.windowWidth_ = cfg.Width p.windowHeight_ = cfg.Height - return } func (p *Game) loadSprite(sprite Spriter, name string, gamer reflect.Value) error { @@ -322,7 +364,7 @@ func (p *Game) loadSprite(sprite Spriter, name string, gamer reflect.Value) erro vSpr.Set(reflect.Zero(vSpr.Type())) base := vSpr.Field(0).Addr().Interface().(*Sprite) base.init(baseDir, p, name, &conf, gamer, p.getSharedImgs()) - p.shapes[name] = sprite + p.sprs[name] = sprite // // init gamer pointer (field 1) *(*uintptr)(unsafe.Pointer(vSpr.Field(1).Addr().Pointer())) = gamer.Addr().Pointer() @@ -334,10 +376,6 @@ func spriteOf(sprite Spriter) *Sprite { return vSpr.Field(0).Addr().Interface().(*Sprite) } -type initer interface { - Main() -} - func (p *Game) loadIndex(g reflect.Value, proj *projConfig) (err error) { if scenes := proj.getScenes(); len(scenes) > 0 { p.baseObj.init("", scenes, proj.getSceneIndex()) @@ -355,17 +393,15 @@ func (p *Game) loadIndex(g reflect.Value, proj *projConfig) (err error) { p.world = ebiten.NewImage(p.worldWidth_, p.worldHeight_) p.mapMode = toMapMode(proj.Map.Mode) - inits := make([]initer, 0, len(proj.Zorder)) + inits := make([]Spriter, 0, len(proj.Zorder)) for _, v := range proj.Zorder { - if name, ok := v.(string); !ok { // not a prototype sprite - inits = p.addSpecialShape(g, v.(specsp), inits) - } else if sp, ok := p.shapes[name]; ok { + if name, ok := v.(string); ok { + sp := p.getSpriteProtoByName(name, g) p.addShape(spriteOf(sp)) - if ini, ok := sp.(initer); ok { - inits = append(inits, ini) - } + inits = append(inits, sp) } else { - return fmt.Errorf("sprite %s is not found", name) + // not a prototype sprite + inits = p.addSpecialShape(g, v.(specsp), inits) } } for _, ini := range inits { @@ -385,14 +421,14 @@ func (p *Game) loadIndex(g reflect.Value, proj *projConfig) (err error) { } p.Camera.init(p, float64(p.windowWidth_), float64(p.windowHeight_), float64(p.worldWidth_), float64(p.worldHeight_)) - ebiten.SetWindowResizable(true) + ebiten.SetWindowResizingMode(ebiten.WindowResizingModeOnlyFullscreenEnabled) if proj.Camera != nil && proj.Camera.On != "" { p.Camera.On(proj.Camera.On) } if loader, ok := g.Addr().Interface().(interface{ OnLoaded() }); ok { loader.OnLoaded() } - //game load success + // game load success p.isLoaded = true return } @@ -427,7 +463,7 @@ func Gopt_Game_Reload(game Gamer, index interface{}) (err error) { type specsp = map[string]interface{} -func (p *Game) addSpecialShape(g reflect.Value, v specsp, inits []initer) []initer { +func (p *Game) addSpecialShape(g reflect.Value, v specsp, inits []Spriter) []Spriter { switch typ := v["type"].(string); typ { case "stageMonitor": if sm, err := newStageMonitor(g, v); err == nil { @@ -445,16 +481,14 @@ func (p *Game) addSpecialShape(g reflect.Value, v specsp, inits []initer) []init return inits } -func (p *Game) addStageSprite(g reflect.Value, v specsp, inits []initer) []initer { +func (p *Game) addStageSprite(g reflect.Value, v specsp, inits []Spriter) []Spriter { target := v["target"].(string) if val := findObjPtr(g, target, 0); val != nil { - if sp, ok := val.(Shape); ok { + if sp, ok := val.(Spriter); ok { dest := spriteOf(sp) applySpriteProps(dest, v) p.addShape(dest) - if ini, ok := val.(initer); ok { - inits = append(inits, ini) - } + inits = append(inits, sp) return inits } } @@ -477,7 +511,7 @@ func (p *Game) addStageSprite(g reflect.Value, v specsp, inits []initer) []inite ] } */ -func (p *Game) addStageSprites(g reflect.Value, v specsp, inits []initer) []initer { +func (p *Game) addStageSprites(g reflect.Value, v specsp, inits []Spriter) []Spriter { target := v["target"].(string) if val := findFieldPtr(g, target, 0); val != nil { fldSlice := reflect.ValueOf(val).Elem() @@ -491,16 +525,8 @@ func (p *Game) addStageSprites(g reflect.Value, v specsp, inits []initer) []init } else { typItemPtr = reflect.PtrTo(typItem) } - if typItemPtr.Implements(tyShape) { - name := typItem.Name() - spr, ok := p.shapes[name] - if !ok { - spr = reflect.New(typItem).Interface().(Spriter) - if err := p.loadSprite(spr, name, g); err != nil { - panic(err) - } - p.shapes[name] = spr - } + if typItemPtr.Implements(tySpriter) { + spr := p.getSpriteProto(typItem, g) items := v["items"].([]interface{}) n := len(items) newSlice := reflect.MakeSlice(typSlice, n, n) @@ -512,9 +538,7 @@ func (p *Game) addStageSprites(g reflect.Value, v specsp, inits []initer) []init } dest, sp := applySprite(newItem, spr, items[i].(specsp)) p.addShape(dest) - if ini, ok := sp.(initer); ok { - inits = append(inits, ini) - } + inits = append(inits, sp) } fldSlice.Set(newSlice) return inits @@ -525,7 +549,7 @@ func (p *Game) addStageSprites(g reflect.Value, v specsp, inits []initer) []init } var ( - tyShape = reflect.TypeOf((*Shape)(nil)).Elem() + tySpriter = reflect.TypeOf((*Spriter)(nil)).Elem() ) // ----------------------------------------------------------------------------- @@ -534,21 +558,15 @@ func (p *Game) runLoop(cfg *Config) (err error) { if debugLoad { log.Println("==> RunLoop") } - if cfg == nil { - cfg = &Config{} - } if !cfg.DontRunOnUnfocused { ebiten.SetRunnableOnUnfocused(true) } if cfg.FullScreen { ebiten.SetFullscreen(true) } + p.isRunned = true p.initEventLoop() - title := cfg.Title - if title == "" { - title = "Game powered by Go+" - } - ebiten.SetWindowTitle(title) + ebiten.SetWindowTitle(cfg.Title) return ebiten.RunGame(p) } diff --git a/sprite.go b/sprite.go index d61e3574..61f2a396 100644 --- a/sprite.go +++ b/sprite.go @@ -205,7 +205,7 @@ func applySpriteProps(dest *Sprite, v specsp) { dest.rotationStyle = toRotationStyle(style.(string)) } if _, ok := v["currentCostumeIndex"]; ok { - // TODO: to be removed + // TODO(xsw): to be removed panic("please change `currentCostumeIndex` => `costumeIndex` in index.json") } if idx, ok := v["costumeIndex"]; ok { @@ -214,14 +214,14 @@ func applySpriteProps(dest *Sprite, v specsp) { dest.isCloned_ = false } -func applySprite(out reflect.Value, sprite Spriter, v specsp) (*Sprite, interface{}) { +func applySprite(out reflect.Value, sprite Spriter, v specsp) (*Sprite, Spriter) { in := reflect.ValueOf(sprite).Elem() - outPtr := out.Addr().Interface() + outPtr := out.Addr().Interface().(Spriter) return cloneSprite(out, outPtr, in, v), outPtr } -func cloneSprite(out reflect.Value, outPtr interface{}, in reflect.Value, v specsp) *Sprite { - dest := spriteOf(outPtr.(Shape)) +func cloneSprite(out reflect.Value, outPtr Spriter, in reflect.Value, v specsp) *Sprite { + dest := spriteOf(outPtr) func() { out.Set(in) for i, n := 0, out.NumField(); i < n; i++ { @@ -232,10 +232,10 @@ func cloneSprite(out reflect.Value, outPtr interface{}, in reflect.Value, v spec } } }() - if v != nil { + if v != nil { // in loadSprite applySpriteProps(dest, v) - } else if ini, ok := outPtr.(initer); ok { - ini.Main() + } else { // in sprite.Clone + outPtr.Main() } return dest } @@ -251,7 +251,7 @@ func Gopt_Sprite_Clone__1(sprite Spriter, data interface{}) { } in := reflect.ValueOf(sprite).Elem() v := reflect.New(in.Type()) - out, outPtr := v.Elem(), v.Interface() + out, outPtr := v.Elem(), v.Interface().(Spriter) dest := cloneSprite(out, outPtr, in, nil) src.g.addClonedShape(src, dest) if dest.hasOnCloned { From e5059bf456aa358b09c4daa1e6128eac4bcd1873 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 14 Mar 2024 02:47:07 +0800 Subject: [PATCH 2/7] game: optional MainEntry/Run --- game.go | 19 +++++++++++++------ tutorial/00-Blank/main.spx | 1 - tutorial/00-Hello/main.spx | 5 ----- tutorial/01-Weather/main.spx | 6 ------ tutorial/01-WeatherPlay/main.spx | 4 +--- tutorial/02-Dragon/Shark.spx | 1 - tutorial/02-Dragon/main.spx | 6 +----- tutorial/03-Clone/main.spx | 5 ----- tutorial/04-Bullet/main.spx | 2 -- tutorial/05-Animation/main.spx | 6 +----- 10 files changed, 16 insertions(+), 39 deletions(-) delete mode 100644 tutorial/00-Hello/main.spx delete mode 100644 tutorial/01-Weather/main.spx diff --git a/game.go b/game.go index f987527a..b59a39f8 100644 --- a/game.go +++ b/game.go @@ -111,7 +111,7 @@ type Spriter interface { } type Gamer interface { - initGame(sprites []Spriter) + initGame(sprites []Spriter) *Game } func (p *Game) getSharedImgs() *sharedImages { @@ -160,7 +160,7 @@ func (p *Game) reset() { p.sprs = make(map[string]Spriter) } -func (p *Game) initGame(sprites []Spriter) { +func (p *Game) initGame(sprites []Spriter) *Game { p.tickMgr.init() p.eventSinks.init(&p.sinkMgr, p) p.sprs = make(map[string]Spriter) @@ -169,12 +169,18 @@ func (p *Game) initGame(sprites []Spriter) { tySpr := reflect.TypeOf(spr).Elem() p.typs[tySpr.Name()] = tySpr } + return p } // Gopt_Game_Main is required by Go+ compiler as the entry of a .gmx project. func Gopt_Game_Main(game Gamer, sprites ...Spriter) { - game.initGame(sprites) - game.(interface{ MainEntry() }).MainEntry() + g := game.initGame(sprites) + if me, ok := game.(interface{ MainEntry() }); ok { + me.MainEntry() + } + if !g.isRunned { + Gopt_Game_Run(game, "assets") + } } // Gopt_Game_Run runs the game. @@ -200,7 +206,6 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { panic(err) } - appName := filepath.Base(os.Args[0]) if !conf.DontParseFlags { f := flag.CommandLine verbose := f.Bool("v", false, "print verbose information") @@ -208,7 +213,7 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { help := f.Bool("h", false, "show help information") flag.Parse() if *help { - fmt.Fprintf(os.Stderr, "Usage: %v [-v -f -h]\n", appName) + fmt.Fprintf(os.Stderr, "Usage: %v [-v -f -h]\n", os.Args[0]) flag.PrintDefaults() return } @@ -218,6 +223,8 @@ func Gopt_Game_Run(game Gamer, resource interface{}, gameConf ...*Config) { conf.FullScreen = *fullscreen } if conf.Title == "" { + dir, _ := os.Getwd() + appName := filepath.Base(dir) conf.Title = appName + " (by Go+ Builder)" } diff --git a/tutorial/00-Blank/main.spx b/tutorial/00-Blank/main.spx index 4c6f974f..e69de29b 100644 --- a/tutorial/00-Blank/main.spx +++ b/tutorial/00-Blank/main.spx @@ -1 +0,0 @@ -run "assets", {Title: "Blank (by Go+ spx engine)"} diff --git a/tutorial/00-Hello/main.spx b/tutorial/00-Hello/main.spx deleted file mode 100644 index ad42f3c2..00000000 --- a/tutorial/00-Hello/main.spx +++ /dev/null @@ -1,5 +0,0 @@ -var ( - Calf Calf -) - -run "assets", {Title: "Hello (by Go+ spx engine)"} diff --git a/tutorial/01-Weather/main.spx b/tutorial/01-Weather/main.spx deleted file mode 100644 index 5d90333e..00000000 --- a/tutorial/01-Weather/main.spx +++ /dev/null @@ -1,6 +0,0 @@ -var ( - Jaime Jaime - Kai Kai -) - -run "assets", {Title: "Weather (by Go+)"} diff --git a/tutorial/01-WeatherPlay/main.spx b/tutorial/01-WeatherPlay/main.spx index 56c7edcf..8e5b331e 100644 --- a/tutorial/01-WeatherPlay/main.spx +++ b/tutorial/01-WeatherPlay/main.spx @@ -1,6 +1,4 @@ var ( - Jaime Jaime - Kai Kai pop Sound recordingBest Sound recordingBye Sound @@ -21,4 +19,4 @@ var ( recordingWinter Sound ) -run "hzip://open.qiniu.us/weather/res.zip", {Title: "Weather (by Go+)"} +run "hzip://open.qiniu.us/weather/res.zip" diff --git a/tutorial/02-Dragon/Shark.spx b/tutorial/02-Dragon/Shark.spx index 8b137891..e69de29b 100644 --- a/tutorial/02-Dragon/Shark.spx +++ b/tutorial/02-Dragon/Shark.spx @@ -1 +0,0 @@ - diff --git a/tutorial/02-Dragon/main.spx b/tutorial/02-Dragon/main.spx index 18937793..f29b86db 100644 --- a/tutorial/02-Dragon/main.spx +++ b/tutorial/02-Dragon/main.spx @@ -1,7 +1,3 @@ var ( - Dragon Dragon - Shark Shark - chomp Sound + chomp Sound ) - -run "assets", {Title: "Dragon (by Go+)"} diff --git a/tutorial/03-Clone/main.spx b/tutorial/03-Clone/main.spx index 3f7ee454..bce19bf2 100644 --- a/tutorial/03-Clone/main.spx +++ b/tutorial/03-Clone/main.spx @@ -1,8 +1,3 @@ var ( - Arrow Arrow - Calf Calf - gid int ) - -run "assets", {Title: "Clone and Destory (by Go+)"} diff --git a/tutorial/04-Bullet/main.spx b/tutorial/04-Bullet/main.spx index dab12ab0..a1bc6fe4 100644 --- a/tutorial/04-Bullet/main.spx +++ b/tutorial/04-Bullet/main.spx @@ -2,5 +2,3 @@ var ( MyAircraft MyAircraft Bullet Bullet ) - -run "assets", {Title: "Bullet (by Go+)"} diff --git a/tutorial/05-Animation/main.spx b/tutorial/05-Animation/main.spx index 84a552ac..2fe990fc 100644 --- a/tutorial/05-Animation/main.spx +++ b/tutorial/05-Animation/main.spx @@ -1,7 +1,3 @@ var ( - Bullet Bullet - SmallEnemy SmallEnemy - explode Sound + explode Sound ) - -run "assets", {Title: "Animation (by Go+)"} From e8b150c77f45b702cdbc4f25f408e9e379b94b62 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 14 Mar 2024 02:56:23 +0800 Subject: [PATCH 3/7] spx test examples --- test/Bananas/main.spx | 2 -- test/Bullet/{res => assets}/1.png | Bin test/Bullet/{res => assets}/index.json | 0 test/Bullet/{res => assets}/sprites/Bullet/30.png | Bin .../{res => assets}/sprites/Bullet/index.json | 0 test/Bullet/main.spx | 5 ----- test/Camera/Monkey.spx | 1 + test/Camera/{res => assets}/index.json | 4 ++++ test/Camera/{res => assets}/sounds/chomp/index.json | 0 test/Camera/{res => assets}/sounds/clap/index.json | 0 .../{res => assets}/sprites/Crocodile/index.json | 0 .../{res => assets}/sprites/Monkey/index.json | 0 test/Camera/main.spx | 2 -- 13 files changed, 5 insertions(+), 9 deletions(-) rename test/Bullet/{res => assets}/1.png (100%) rename test/Bullet/{res => assets}/index.json (100%) rename test/Bullet/{res => assets}/sprites/Bullet/30.png (100%) rename test/Bullet/{res => assets}/sprites/Bullet/index.json (100%) delete mode 100644 test/Bullet/main.spx rename test/Camera/{res => assets}/index.json (77%) rename test/Camera/{res => assets}/sounds/chomp/index.json (100%) rename test/Camera/{res => assets}/sounds/clap/index.json (100%) rename test/Camera/{res => assets}/sprites/Crocodile/index.json (100%) rename test/Camera/{res => assets}/sprites/Monkey/index.json (100%) diff --git a/test/Bananas/main.spx b/test/Bananas/main.spx index 9c204fba..87b9bef6 100644 --- a/test/Bananas/main.spx +++ b/test/Bananas/main.spx @@ -3,5 +3,3 @@ var ( Monkey *Monkey Red *Red ) - -run "assets", {Title: "Bananas (by Go+)"} diff --git a/test/Bullet/res/1.png b/test/Bullet/assets/1.png similarity index 100% rename from test/Bullet/res/1.png rename to test/Bullet/assets/1.png diff --git a/test/Bullet/res/index.json b/test/Bullet/assets/index.json similarity index 100% rename from test/Bullet/res/index.json rename to test/Bullet/assets/index.json diff --git a/test/Bullet/res/sprites/Bullet/30.png b/test/Bullet/assets/sprites/Bullet/30.png similarity index 100% rename from test/Bullet/res/sprites/Bullet/30.png rename to test/Bullet/assets/sprites/Bullet/30.png diff --git a/test/Bullet/res/sprites/Bullet/index.json b/test/Bullet/assets/sprites/Bullet/index.json similarity index 100% rename from test/Bullet/res/sprites/Bullet/index.json rename to test/Bullet/assets/sprites/Bullet/index.json diff --git a/test/Bullet/main.spx b/test/Bullet/main.spx deleted file mode 100644 index 3247b23b..00000000 --- a/test/Bullet/main.spx +++ /dev/null @@ -1,5 +0,0 @@ -var ( - Bullet Bullet -) - -run "res", {Title: "Bullet (by Go+)"} diff --git a/test/Camera/Monkey.spx b/test/Camera/Monkey.spx index b25c8eb9..38e300d0 100644 --- a/test/Camera/Monkey.spx +++ b/test/Camera/Monkey.spx @@ -1,6 +1,7 @@ onClick => { animate "clap" } + onStart => { println "Monkey onStart" for { diff --git a/test/Camera/res/index.json b/test/Camera/assets/index.json similarity index 77% rename from test/Camera/res/index.json rename to test/Camera/assets/index.json index 70e32432..40596b94 100644 --- a/test/Camera/res/index.json +++ b/test/Camera/assets/index.json @@ -1,4 +1,8 @@ { + "run": { + "width": 640, + "height": 480 + }, "scenes": [ { "name": "backdrop1", diff --git a/test/Camera/res/sounds/chomp/index.json b/test/Camera/assets/sounds/chomp/index.json similarity index 100% rename from test/Camera/res/sounds/chomp/index.json rename to test/Camera/assets/sounds/chomp/index.json diff --git a/test/Camera/res/sounds/clap/index.json b/test/Camera/assets/sounds/clap/index.json similarity index 100% rename from test/Camera/res/sounds/clap/index.json rename to test/Camera/assets/sounds/clap/index.json diff --git a/test/Camera/res/sprites/Crocodile/index.json b/test/Camera/assets/sprites/Crocodile/index.json similarity index 100% rename from test/Camera/res/sprites/Crocodile/index.json rename to test/Camera/assets/sprites/Crocodile/index.json diff --git a/test/Camera/res/sprites/Monkey/index.json b/test/Camera/assets/sprites/Monkey/index.json similarity index 100% rename from test/Camera/res/sprites/Monkey/index.json rename to test/Camera/assets/sprites/Monkey/index.json diff --git a/test/Camera/main.spx b/test/Camera/main.spx index 4163e3a2..ea457596 100644 --- a/test/Camera/main.spx +++ b/test/Camera/main.spx @@ -8,5 +8,3 @@ var ( func OnLoaded() { println "onLoad" } - -run "res", {Title: "Camera (by Go+)", Width: 640, Height: 480} From 283a0808406a163e5265510c31898029982b33a4 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 14 Mar 2024 03:04:59 +0800 Subject: [PATCH 4/7] examples: CameraTouching/Dinosaur --- test/CameraTouching/{res => assets}/img/1.jpg | Bin test/CameraTouching/{res => assets}/index.json | 4 ++++ .../{res => assets}/sounds/chomp/index.json | 0 .../{res => assets}/sounds/clap/index.json | 0 .../{res => assets}/sprites/Box/index.json | 0 .../{res => assets}/sprites/Crocodile/index.json | 0 .../{res => assets}/sprites/Monkey/index.json | 0 test/CameraTouching/main.spx | 2 +- test/Dinosaur/{res => assets}/6.png | Bin test/Dinosaur/{res => assets}/index.json | 0 .../{res => assets}/sprites/Bird/index.json | 0 .../{res => assets}/sprites/Dinosaur/index.json | 0 .../{res => assets}/sprites/GameOver/index.json | 0 .../{res => assets}/sprites/LargeTree/index.json | 0 .../{res => assets}/sprites/Road/index.json | 0 .../{res => assets}/sprites/SmallTree/index.json | 0 test/Dinosaur/{res => assets}/sprites/common.png | Bin test/Dinosaur/main.spx | 10 ---------- 18 files changed, 5 insertions(+), 11 deletions(-) rename test/CameraTouching/{res => assets}/img/1.jpg (100%) rename test/CameraTouching/{res => assets}/index.json (88%) rename test/CameraTouching/{res => assets}/sounds/chomp/index.json (100%) rename test/CameraTouching/{res => assets}/sounds/clap/index.json (100%) rename test/CameraTouching/{res => assets}/sprites/Box/index.json (100%) rename test/CameraTouching/{res => assets}/sprites/Crocodile/index.json (100%) rename test/CameraTouching/{res => assets}/sprites/Monkey/index.json (100%) rename test/Dinosaur/{res => assets}/6.png (100%) rename test/Dinosaur/{res => assets}/index.json (100%) rename test/Dinosaur/{res => assets}/sprites/Bird/index.json (100%) rename test/Dinosaur/{res => assets}/sprites/Dinosaur/index.json (100%) rename test/Dinosaur/{res => assets}/sprites/GameOver/index.json (100%) rename test/Dinosaur/{res => assets}/sprites/LargeTree/index.json (100%) rename test/Dinosaur/{res => assets}/sprites/Road/index.json (100%) rename test/Dinosaur/{res => assets}/sprites/SmallTree/index.json (100%) rename test/Dinosaur/{res => assets}/sprites/common.png (100%) delete mode 100644 test/Dinosaur/main.spx diff --git a/test/CameraTouching/res/img/1.jpg b/test/CameraTouching/assets/img/1.jpg similarity index 100% rename from test/CameraTouching/res/img/1.jpg rename to test/CameraTouching/assets/img/1.jpg diff --git a/test/CameraTouching/res/index.json b/test/CameraTouching/assets/index.json similarity index 88% rename from test/CameraTouching/res/index.json rename to test/CameraTouching/assets/index.json index c6e69b20..b44b20b3 100644 --- a/test/CameraTouching/res/index.json +++ b/test/CameraTouching/assets/index.json @@ -1,4 +1,8 @@ { + "run": { + "width": 640, + "height": 480 + }, "scenes": [ { "name": "backdrop1", diff --git a/test/CameraTouching/res/sounds/chomp/index.json b/test/CameraTouching/assets/sounds/chomp/index.json similarity index 100% rename from test/CameraTouching/res/sounds/chomp/index.json rename to test/CameraTouching/assets/sounds/chomp/index.json diff --git a/test/CameraTouching/res/sounds/clap/index.json b/test/CameraTouching/assets/sounds/clap/index.json similarity index 100% rename from test/CameraTouching/res/sounds/clap/index.json rename to test/CameraTouching/assets/sounds/clap/index.json diff --git a/test/CameraTouching/res/sprites/Box/index.json b/test/CameraTouching/assets/sprites/Box/index.json similarity index 100% rename from test/CameraTouching/res/sprites/Box/index.json rename to test/CameraTouching/assets/sprites/Box/index.json diff --git a/test/CameraTouching/res/sprites/Crocodile/index.json b/test/CameraTouching/assets/sprites/Crocodile/index.json similarity index 100% rename from test/CameraTouching/res/sprites/Crocodile/index.json rename to test/CameraTouching/assets/sprites/Crocodile/index.json diff --git a/test/CameraTouching/res/sprites/Monkey/index.json b/test/CameraTouching/assets/sprites/Monkey/index.json similarity index 100% rename from test/CameraTouching/res/sprites/Monkey/index.json rename to test/CameraTouching/assets/sprites/Monkey/index.json diff --git a/test/CameraTouching/main.spx b/test/CameraTouching/main.spx index 62a71836..cbcce8d3 100644 --- a/test/CameraTouching/main.spx +++ b/test/CameraTouching/main.spx @@ -6,4 +6,4 @@ var ( clap Sound ) -run "res", {Title: "CameraTouching (by Go+)", Width: 640, Height: 480} +run "assets", {Title: "CameraTouching (by Go+)", Width: 640, Height: 480} diff --git a/test/Dinosaur/res/6.png b/test/Dinosaur/assets/6.png similarity index 100% rename from test/Dinosaur/res/6.png rename to test/Dinosaur/assets/6.png diff --git a/test/Dinosaur/res/index.json b/test/Dinosaur/assets/index.json similarity index 100% rename from test/Dinosaur/res/index.json rename to test/Dinosaur/assets/index.json diff --git a/test/Dinosaur/res/sprites/Bird/index.json b/test/Dinosaur/assets/sprites/Bird/index.json similarity index 100% rename from test/Dinosaur/res/sprites/Bird/index.json rename to test/Dinosaur/assets/sprites/Bird/index.json diff --git a/test/Dinosaur/res/sprites/Dinosaur/index.json b/test/Dinosaur/assets/sprites/Dinosaur/index.json similarity index 100% rename from test/Dinosaur/res/sprites/Dinosaur/index.json rename to test/Dinosaur/assets/sprites/Dinosaur/index.json diff --git a/test/Dinosaur/res/sprites/GameOver/index.json b/test/Dinosaur/assets/sprites/GameOver/index.json similarity index 100% rename from test/Dinosaur/res/sprites/GameOver/index.json rename to test/Dinosaur/assets/sprites/GameOver/index.json diff --git a/test/Dinosaur/res/sprites/LargeTree/index.json b/test/Dinosaur/assets/sprites/LargeTree/index.json similarity index 100% rename from test/Dinosaur/res/sprites/LargeTree/index.json rename to test/Dinosaur/assets/sprites/LargeTree/index.json diff --git a/test/Dinosaur/res/sprites/Road/index.json b/test/Dinosaur/assets/sprites/Road/index.json similarity index 100% rename from test/Dinosaur/res/sprites/Road/index.json rename to test/Dinosaur/assets/sprites/Road/index.json diff --git a/test/Dinosaur/res/sprites/SmallTree/index.json b/test/Dinosaur/assets/sprites/SmallTree/index.json similarity index 100% rename from test/Dinosaur/res/sprites/SmallTree/index.json rename to test/Dinosaur/assets/sprites/SmallTree/index.json diff --git a/test/Dinosaur/res/sprites/common.png b/test/Dinosaur/assets/sprites/common.png similarity index 100% rename from test/Dinosaur/res/sprites/common.png rename to test/Dinosaur/assets/sprites/common.png diff --git a/test/Dinosaur/main.spx b/test/Dinosaur/main.spx deleted file mode 100644 index 78f3bed3..00000000 --- a/test/Dinosaur/main.spx +++ /dev/null @@ -1,10 +0,0 @@ -var ( - Bird Bird - Dinosaur Dinosaur - LargeTree LargeTree - SmallTree SmallTree - GameOver GameOver - Road Road -) - -run "res", {Title: "Dinosaur (by Go+)"} From 9078e3a7c3b6098ba4c3a1243fa580177c0b2a97 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 14 Mar 2024 03:09:31 +0800 Subject: [PATCH 5/7] examples: Hello/Measure --- test/Hello/{res => assets}/img/1.jpg | Bin test/Hello/{res => assets}/img/banana.png | Bin test/Hello/{res => assets}/img/lake.jpg | Bin test/Hello/{res => assets}/index.json | 0 .../{res => assets}/sprites/Crocodile/index.json | 0 .../Hello/{res => assets}/sprites/Monkey/index.json | 0 test/Hello/main.spx | 2 -- test/Measure/{res => assets}/index.json | 0 .../{res => assets}/sprites/Monkey/index.json | 0 test/Measure/main.spx | 2 -- 10 files changed, 4 deletions(-) rename test/Hello/{res => assets}/img/1.jpg (100%) rename test/Hello/{res => assets}/img/banana.png (100%) rename test/Hello/{res => assets}/img/lake.jpg (100%) rename test/Hello/{res => assets}/index.json (100%) rename test/Hello/{res => assets}/sprites/Crocodile/index.json (100%) rename test/Hello/{res => assets}/sprites/Monkey/index.json (100%) rename test/Measure/{res => assets}/index.json (100%) rename test/Measure/{res => assets}/sprites/Monkey/index.json (100%) diff --git a/test/Hello/res/img/1.jpg b/test/Hello/assets/img/1.jpg similarity index 100% rename from test/Hello/res/img/1.jpg rename to test/Hello/assets/img/1.jpg diff --git a/test/Hello/res/img/banana.png b/test/Hello/assets/img/banana.png similarity index 100% rename from test/Hello/res/img/banana.png rename to test/Hello/assets/img/banana.png diff --git a/test/Hello/res/img/lake.jpg b/test/Hello/assets/img/lake.jpg similarity index 100% rename from test/Hello/res/img/lake.jpg rename to test/Hello/assets/img/lake.jpg diff --git a/test/Hello/res/index.json b/test/Hello/assets/index.json similarity index 100% rename from test/Hello/res/index.json rename to test/Hello/assets/index.json diff --git a/test/Hello/res/sprites/Crocodile/index.json b/test/Hello/assets/sprites/Crocodile/index.json similarity index 100% rename from test/Hello/res/sprites/Crocodile/index.json rename to test/Hello/assets/sprites/Crocodile/index.json diff --git a/test/Hello/res/sprites/Monkey/index.json b/test/Hello/assets/sprites/Monkey/index.json similarity index 100% rename from test/Hello/res/sprites/Monkey/index.json rename to test/Hello/assets/sprites/Monkey/index.json diff --git a/test/Hello/main.spx b/test/Hello/main.spx index d756e5b3..8daf6698 100644 --- a/test/Hello/main.spx +++ b/test/Hello/main.spx @@ -2,5 +2,3 @@ var ( Monkey *Monkey Crocodile *Crocodile ) - -run "res", {Title: "Hello (by Go+)"} diff --git a/test/Measure/res/index.json b/test/Measure/assets/index.json similarity index 100% rename from test/Measure/res/index.json rename to test/Measure/assets/index.json diff --git a/test/Measure/res/sprites/Monkey/index.json b/test/Measure/assets/sprites/Monkey/index.json similarity index 100% rename from test/Measure/res/sprites/Monkey/index.json rename to test/Measure/assets/sprites/Monkey/index.json diff --git a/test/Measure/main.spx b/test/Measure/main.spx index d8551837..b821c708 100644 --- a/test/Measure/main.spx +++ b/test/Measure/main.spx @@ -1,5 +1,3 @@ var ( Monkey Monkey ) - -run "res", {Title: "Measure (by Go+)"} From 985bac22c6042f97b5c966a7af715f58dd196010 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 14 Mar 2024 03:22:17 +0800 Subject: [PATCH 6/7] workflow: GenGo --- .github/dependabot.yml | 10 +++++++++- .github/workflows/go.yml | 10 +++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b444581e..c8c3b8ae 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,18 @@ # To get started with Dependabot version updates, you'll need to specify which # package ecosystems to update and where the package manifests are located. # Please see the documentation for all configuration options: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates version: 2 updates: + - package-ecosystem: github-actions + directory: / + labels: + - dependabot + - actions + schedule: + interval: daily + - package-ecosystem: "gomod" # See documentation for possible values directory: "/" # Location of package manifests schedule: diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cc01fc6a..bb353ff8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,10 +13,11 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v3 + - name: Set up Go/Go+ + uses: goplus/setup-goplus@v1.1.0 with: - go-version: 1.18 + go-version: "1.18" + gop-version: "main" - name: Get dependencies run: sudo apt-get update && sudo apt-get install gcc libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev libx11-dev xorg-dev libasound2-dev libopenal-dev @@ -27,3 +28,6 @@ jobs: - name: Test run: go test -v ./... + + - name: GenGo + run: gop go ./... From 4a367a20c6f8827033e268774cbef1c41d998588 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 14 Mar 2024 03:34:44 +0800 Subject: [PATCH 7/7] temporary disable example Quote --- test/{Quote => _Quote}/Crocodile.spx | 0 test/{Quote => _Quote}/Monkey.spx | 0 test/{Quote => _Quote}/main.spx | 0 test/{Quote => _Quote}/res/index.json | 0 test/{Quote => _Quote}/res/sounds/chomp/index.json | 0 test/{Quote => _Quote}/res/sounds/clap/index.json | 0 test/{Quote => _Quote}/res/sprites/Crocodile/index.json | 0 test/{Quote => _Quote}/res/sprites/Monkey/index.json | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename test/{Quote => _Quote}/Crocodile.spx (100%) rename test/{Quote => _Quote}/Monkey.spx (100%) rename test/{Quote => _Quote}/main.spx (100%) rename test/{Quote => _Quote}/res/index.json (100%) rename test/{Quote => _Quote}/res/sounds/chomp/index.json (100%) rename test/{Quote => _Quote}/res/sounds/clap/index.json (100%) rename test/{Quote => _Quote}/res/sprites/Crocodile/index.json (100%) rename test/{Quote => _Quote}/res/sprites/Monkey/index.json (100%) diff --git a/test/Quote/Crocodile.spx b/test/_Quote/Crocodile.spx similarity index 100% rename from test/Quote/Crocodile.spx rename to test/_Quote/Crocodile.spx diff --git a/test/Quote/Monkey.spx b/test/_Quote/Monkey.spx similarity index 100% rename from test/Quote/Monkey.spx rename to test/_Quote/Monkey.spx diff --git a/test/Quote/main.spx b/test/_Quote/main.spx similarity index 100% rename from test/Quote/main.spx rename to test/_Quote/main.spx diff --git a/test/Quote/res/index.json b/test/_Quote/res/index.json similarity index 100% rename from test/Quote/res/index.json rename to test/_Quote/res/index.json diff --git a/test/Quote/res/sounds/chomp/index.json b/test/_Quote/res/sounds/chomp/index.json similarity index 100% rename from test/Quote/res/sounds/chomp/index.json rename to test/_Quote/res/sounds/chomp/index.json diff --git a/test/Quote/res/sounds/clap/index.json b/test/_Quote/res/sounds/clap/index.json similarity index 100% rename from test/Quote/res/sounds/clap/index.json rename to test/_Quote/res/sounds/clap/index.json diff --git a/test/Quote/res/sprites/Crocodile/index.json b/test/_Quote/res/sprites/Crocodile/index.json similarity index 100% rename from test/Quote/res/sprites/Crocodile/index.json rename to test/_Quote/res/sprites/Crocodile/index.json diff --git a/test/Quote/res/sprites/Monkey/index.json b/test/_Quote/res/sprites/Monkey/index.json similarity index 100% rename from test/Quote/res/sprites/Monkey/index.json rename to test/_Quote/res/sprites/Monkey/index.json