diff --git a/camera.go b/camera.go index 7f49ec1b..82a33f97 100644 --- a/camera.go +++ b/camera.go @@ -59,9 +59,9 @@ func (c *Camera) worldToScreen(point *math32.Vector2) *math32.Vector2 { } */ -func (c *Camera) On(obj interface{}) { +func (c *Camera) on(obj interface{}) { switch v := obj.(type) { - case string: + case SpriteName: sp := c.g.findSprite(v) if sp == nil { log.Println("Camera.On: sprite not found -", v) @@ -83,6 +83,22 @@ func (c *Camera) On(obj interface{}) { c.on_ = obj } +func (c *Camera) On__0(sprite Sprite) { + c.on(sprite) +} + +func (c *Camera) On__1(sprite *SpriteImpl) { + c.on(sprite) +} + +func (c *Camera) On__2(sprite SpriteName) { + c.on(sprite) +} + +func (c *Camera) On__3(obj specialObj) { + c.on(obj) +} + func (c *Camera) updateOnObj() { switch v := c.on_.(type) { case *SpriteImpl: diff --git a/event.go b/event.go index 3a77da6e..e789bebc 100644 --- a/event.go +++ b/event.go @@ -213,17 +213,17 @@ func (p *eventSinkMgr) doWhenIReceive(msg string, data interface{}, wait bool) { }) } -func (p *eventSinkMgr) doWhenBackdropChanged(name string, wait bool) { +func (p *eventSinkMgr) doWhenBackdropChanged(name BackdropName, wait bool) { p.allWhenBackdropChanged.call(wait, name, func(ev *eventSink) { - ev.sink.(func(string))(name) + ev.sink.(func(BackdropName))(name) }) } // ------------------------------------------------------------------------------------- type IEventSinks interface { OnAnyKey(onKey func(key Key)) - OnBackdrop__0(onBackdrop func(name string)) - OnBackdrop__1(name string, onBackdrop func()) + OnBackdrop__0(onBackdrop func(name BackdropName)) + OnBackdrop__1(name BackdropName, onBackdrop func()) OnClick(onClick func()) OnKey__0(key Key, onKey func()) OnKey__1(keys []Key, onKey func(Key)) @@ -361,7 +361,7 @@ func (p *eventSinks) OnMsg__1(msg string, onMsg func()) { } } -func (p *eventSinks) OnBackdrop__0(onBackdrop func(name string)) { +func (p *eventSinks) OnBackdrop__0(onBackdrop func(name BackdropName)) { p.allWhenBackdropChanged = &eventSink{ prev: p.allWhenBackdropChanged, pthis: p.pthis, @@ -369,18 +369,18 @@ func (p *eventSinks) OnBackdrop__0(onBackdrop func(name string)) { } } -func (p *eventSinks) OnBackdrop__1(name string, onBackdrop func()) { +func (p *eventSinks) OnBackdrop__1(name BackdropName, onBackdrop func()) { p.allWhenBackdropChanged = &eventSink{ prev: p.allWhenBackdropChanged, pthis: p.pthis, - sink: func(name string) { + sink: func(name BackdropName) { if debugEvent { log.Println("==> onBackdrop", name, nameOf(p.pthis)) } onBackdrop() }, cond: func(data interface{}) bool { - return data.(string) == name + return data.(BackdropName) == name }, } } diff --git a/game.go b/game.go index 0ee16967..8a569076 100644 --- a/game.go +++ b/game.go @@ -473,7 +473,7 @@ func (p *Game) loadIndex(g reflect.Value, proj *projConfig) (err error) { ebiten.SetWindowResizingMode(ebiten.WindowResizingModeOnlyFullscreenEnabled) if proj.Camera != nil && proj.Camera.On != "" { - p.Camera.On(proj.Camera.On) + p.Camera.On__2(proj.Camera.On) } if loader, ok := g.Addr().Interface().(interface{ OnLoaded() }); ok { loader.OnLoaded() @@ -860,7 +860,7 @@ func (p *Game) touchingSpriteBy(dst *SpriteImpl, name string) *SpriteImpl { func (p *Game) objectPos(obj interface{}) (float64, float64) { switch v := obj.(type) { - case string: + case SpriteName: if sp := p.findSprite(v); sp != nil { return sp.getXY() } @@ -1033,7 +1033,7 @@ func (p *Game) doFindSprite(src Shape) int { return -1 } -func (p *Game) findSprite(name string) *SpriteImpl { +func (p *Game) findSprite(name SpriteName) *SpriteImpl { for _, item := range p.items { if sp, ok := item.(*SpriteImpl); ok { if !sp.isCloned_ && sp.name == name { @@ -1045,7 +1045,6 @@ func (p *Game) findSprite(name string) *SpriteImpl { } // ----------------------------------------------------------------------------- - func (p *Game) drawBackground(dc drawContext) { c := p.costumes[p.costumeIndex_] img, _, _ := c.needImage(p.fs) @@ -1156,7 +1155,9 @@ func (p *Game) onHit(hc hitContext) (hr hitResult, ok bool) { // ----------------------------------------------------------------------------- -func (p *Game) BackdropName() string { +type BackdropName = string + +func (p *Game) BackdropName() BackdropName { return p.getCostumeName() } @@ -1166,24 +1167,64 @@ func (p *Game) BackdropIndex() int { // StartBackdrop func: // -// StartBackdrop(backdropName) or -// StartBackdrop(backdropIndex) or +// StartBackdrop(backdrop) or +// StartBackdrop(index) or // StartBackdrop(spx.Next) // StartBackdrop(spx.Prev) -func (p *Game) StartBackdrop(backdrop interface{}, wait ...bool) { +func (p *Game) startBackdrop(backdrop interface{}, wait bool) { if p.goSetCostume(backdrop) { p.windowWidth_ = 0 p.doWindowSize() - p.doWhenBackdropChanged(p.getCostumeName(), wait != nil && wait[0]) + p.doWhenBackdropChanged(p.getCostumeName(), wait) } } -func (p *Game) NextBackdrop(wait ...bool) { - p.StartBackdrop(Next, wait...) +func (p *Game) StartBackdrop__0(backdrop BackdropName) { + p.startBackdrop(backdrop, false) +} + +func (p *Game) StartBackdrop__1(backdrop BackdropName, wait bool) { + p.startBackdrop(backdrop, wait) +} + +func (p *Game) StartBackdrop__2(index int) { + p.startBackdrop(index, false) +} + +func (p *Game) StartBackdrop__3(index int, wait bool) { + p.startBackdrop(index, wait) +} + +func (p *Game) StartBackdrop__4(index float64) { + p.startBackdrop(index, false) +} + +func (p *Game) StartBackdrop__5(index float64, wait bool) { + p.startBackdrop(index, wait) } -func (p *Game) PrevBackdrop(wait ...bool) { - p.StartBackdrop(Prev, wait...) +func (p *Game) StartBackdrop__6(action switchAction) { + p.startBackdrop(action, false) +} + +func (p *Game) StartBackdrop__7(action switchAction, wait bool) { + p.startBackdrop(action, wait) +} + +func (p *Game) NextBackdrop__0() { + p.StartBackdrop__6(Next) +} + +func (p *Game) NextBackdrop__1(wait bool) { + p.StartBackdrop__7(Next, wait) +} + +func (p *Game) PrevBackdrop__0() { + p.StartBackdrop__6(Prev) +} + +func (p *Game) PrevBackdrop__1(wait bool) { + p.StartBackdrop__7(Prev, wait) } // ----------------------------------------------------------------------------- @@ -1282,6 +1323,8 @@ func (p *Game) ClearSoundEffects() { type Sound *soundConfig +type SoundName = string + func (p *Game) canBindSound(name string) bool { // auto bind the sound, if assets/sounds/{name}/index.json exists. prefix := "sounds/" + name @@ -1293,7 +1336,7 @@ func (p *Game) canBindSound(name string) bool { return true } -func (p *Game) loadSound(name string) (media Sound, err error) { +func (p *Game) loadSound(name SoundName) (media Sound, err error) { if media, ok := p.sounds.audios[name]; ok { return media, nil } @@ -1317,9 +1360,6 @@ func (p *Game) loadSound(name string) (media Sound, err error) { // Play(video) -- maybe // Play(media, wait) -- sync // Play(media, opts) -// Play(mediaName) -// Play(mediaName, wait) -- sync -// Play(mediaName, opts) func (p *Game) Play__0(media Sound) { p.Play__2(media, &PlayOptions{}) } @@ -1338,21 +1378,22 @@ func (p *Game) Play__2(media Sound, action *PlayOptions) { panic(err) } } -func (p *Game) Play__3(mediaName string) { - p.Play__5(mediaName, &PlayOptions{}) + +func (p *Game) Play__3(media SoundName) { + p.Play__5(media, &PlayOptions{}) } -func (p *Game) Play__4(mediaName string, wait bool) { - p.Play__5(mediaName, &PlayOptions{Wait: wait}) +func (p *Game) Play__4(media SoundName, wait bool) { + p.Play__5(media, &PlayOptions{Wait: wait}) } -func (p *Game) Play__5(mediaName string, action *PlayOptions) { - media, err := p.loadSound(mediaName) +func (p *Game) Play__5(media SoundName, action *PlayOptions) { + m, err := p.loadSound(media) if err != nil { log.Println(err) return } - p.Play__2(media, action) + p.Play__2(m, action) } func (p *Game) StopAllSounds() { @@ -1433,7 +1474,7 @@ type ShapeGetter interface { // Instead of being used directly, it is meant to be called by `Gopt_Game_Gopx_GetWidget` only. // We extract `GetWidget_` to keep `Gopt_Game_Gopx_GetWidget` simple, which simplifies work in ispx, // see details in https://github.com/goplus/builder/issues/765#issuecomment-2313915805. -func GetWidget_(sg ShapeGetter, name string) Widget { +func GetWidget_(sg ShapeGetter, name WidgetName) Widget { items := sg.getAllShapes() for _, item := range items { widget, ok := item.(Widget) @@ -1445,7 +1486,7 @@ func GetWidget_(sg ShapeGetter, name string) Widget { } // GetWidget returns the widget instance (in given type) with given name. It panics if not found. -func Gopt_Game_Gopx_GetWidget[T any](sg ShapeGetter, name string) *T { +func Gopt_Game_Gopx_GetWidget[T any](sg ShapeGetter, name WidgetName) *T { widget := GetWidget_(sg, name) if result, ok := widget.(interface{}).(*T); ok { return result diff --git a/monitor.go b/monitor.go index c32a817e..c024f579 100644 --- a/monitor.go +++ b/monitor.go @@ -37,7 +37,7 @@ import ( // Monitor class. type Monitor struct { game *Game - name string + name WidgetName size float64 target string val string @@ -304,7 +304,7 @@ func (p *Monitor) hit(hc hitContext) (hr hitResult, ok bool) { // ------------------------------------------------------------------------------------- // IWidget -func (pself *Monitor) GetName() string { +func (pself *Monitor) GetName() WidgetName { return pself.name } diff --git a/spbase.go b/spbase.go index 8e3c2574..b2dc2837 100644 --- a/spbase.go +++ b/spbase.go @@ -174,7 +174,7 @@ func (p *imageLoaderByCostumeSet) load(fs spxfs.Dir, pt *imagePoint) (gdi.Image, // ------------------------------------------------------------------------------------- type costume struct { - name string + name SpriteCostumeName img delayloadImage faceRight float64 bitmapResolution int @@ -296,7 +296,7 @@ func initCSPart(p *baseObj, img *costumeSetImage, faceRight float64, bitmapResol } } -func addCostumeWith(p *baseObj, name string, img *costumeSetImage, faceRight float64, i, bitmapResolution int) { +func addCostumeWith(p *baseObj, name SpriteCostumeName, img *costumeSetImage, faceRight float64, i, bitmapResolution int) { c := newCostumeWith(name, img, faceRight, i, bitmapResolution) p.costumes = append(p.costumes, c) } @@ -334,7 +334,7 @@ func (p *baseObj) initFrom(src *baseObj) { p.costumeIndex_ = src.costumeIndex_ } -func (p *baseObj) findCostume(name string) int { +func (p *baseObj) findCostume(name SpriteCostumeName) int { for i, c := range p.costumes { if c.name == name { return i @@ -345,7 +345,7 @@ func (p *baseObj) findCostume(name string) int { func (p *baseObj) goSetCostume(val interface{}) bool { switch v := val.(type) { - case string: + case SpriteCostumeName: return p.setCostumeByName(v) case int: return p.setCostumeByIndex(v) @@ -373,8 +373,7 @@ func (p *baseObj) setCostumeByIndex(idx int) bool { } return false } - -func (p *baseObj) setCostumeByName(name string) bool { +func (p *baseObj) setCostumeByName(name SpriteCostumeName) bool { if idx := p.findCostume(name); idx >= 0 { return p.setCostumeByIndex(idx) } @@ -393,7 +392,7 @@ func (p *baseObj) getCostumeIndex() int { return p.costumeIndex_ } -func (p *baseObj) getCostumeName() string { +func (p *baseObj) getCostumeName() SpriteCostumeName { return p.costumes[p.costumeIndex_].name } diff --git a/sprite.go b/sprite.go index 337c1a71..4c25e4a5 100644 --- a/sprite.go +++ b/sprite.go @@ -111,7 +111,7 @@ type Sprite interface { Shape Main() - Animate(name string) + Animate(name SpriteAnimationName) Ask(msg interface{}) BounceOffEdge() Bounds() *math32.RotatedRect @@ -128,16 +128,24 @@ type Sprite interface { ClearGraphEffects() CostumeHeight() float64 CostumeIndex() int - CostumeName() string + CostumeName() SpriteCostumeName CostumeWidth() float64 DeleteThisClone() Destroy() Die() - DistanceTo(obj interface{}) float64 + DistanceTo__0(sprite Sprite) float64 + DistanceTo__1(sprite SpriteName) float64 + DistanceTo__2(obj specialObj) float64 + DistanceTo__3(pos Pos) float64 Glide__0(x, y float64, secs float64) - Glide__1(obj interface{}, secs float64) + Glide__1(sprite Sprite, secs float64) + Glide__2(sprite SpriteName, secs float64) + Glide__3(obj specialObj, secs float64) + Glide__4(pos Pos, secs float64) GoBackLayers(n int) - Goto(obj interface{}) + Goto__0(sprite Sprite) + Goto__1(sprite SpriteName) + Goto__2(obj specialObj) GotoBack() GotoFront() Heading() float64 @@ -153,8 +161,8 @@ type Sprite interface { OnMoving__1(onMoving func()) OnTouchStart__0(onTouchStart func(Sprite)) OnTouchStart__1(onTouchStart func()) - OnTouchStart__2(name string, onTouchStart func(Sprite)) - OnTouchStart__3(name string, onTouchStart func()) + OnTouchStart__2(sprite SpriteName, onTouchStart func(Sprite)) + OnTouchStart__3(sprite SpriteName, onTouchStart func()) OnTurning__0(onTurning func(ti *TurningInfo)) OnTurning__1(onTurning func()) Parent() *Game @@ -163,9 +171,14 @@ type Sprite interface { PrevCostume() Quote__0(message string) Quote__1(message string, secs float64) - Quote__2(message, description string, secs ...float64) - Say(msg interface{}, secs ...float64) - SetCostume(costume interface{}) + Quote__2(message, description string) + Quote__3(message, description string, secs float64) + Say__0(msg interface{}) + Say__1(msg interface{}, secs float64) + SetCostume__0(costume SpriteCostumeName) + SetCostume__1(index int) + SetCostume__2(index float64) + SetCostume__3(action switchAction) SetDying() SetEffect(kind EffectKind, val float64) SetHeading(dir float64) @@ -184,17 +197,32 @@ type Sprite interface { Stamp() Step__0(step float64) Step__1(step int) - Step__2(step float64, animname string) - Think(msg interface{}, secs ...float64) - Touching(obj interface{}) bool + Step__2(step float64, animation SpriteAnimationName) + Think__0(msg interface{}) + Think__1(msg interface{}, secs float64) + Touching__0(sprite SpriteName) bool + Touching__1(sprite Sprite) bool + Touching__2(obj specialObj) bool TouchingColor(color Color) bool - Turn(val interface{}) - TurnTo(obj interface{}) + Turn__0(degree float64) + Turn__1(dir specialDir) + Turn__2(ti *TurningInfo) + TurnTo__0(sprite Sprite) + TurnTo__1(sprite SpriteName) + TurnTo__2(obj specialObj) + TurnTo__3(degree float64) + TurnTo__4(dir specialDir) Visible() bool Xpos() float64 Ypos() float64 } +type SpriteName = string + +type SpriteCostumeName = string + +type SpriteAnimationName = string + type SpriteImpl struct { baseObj eventSinks @@ -211,10 +239,10 @@ type SpriteImpl struct { sayObj *sayOrThinker quoteObj *quoter - animations map[string]*aniConfig + animations map[SpriteAnimationName]*aniConfig greffUniforms map[string]interface{} // graphic effects animBindings map[string]string - defaultAnimation string + defaultAnimation SpriteAnimationName penColor color.RGBA penShade float64 @@ -545,17 +573,17 @@ func (p *SpriteImpl) OnTouchStart__1(onTouchStart func()) { }) } -func (p *SpriteImpl) OnTouchStart__2(name string, onTouchStart func(Sprite)) { - p.OnTouchStart__0(func(sprite Sprite) { - impl := spriteOf(sprite) - if impl != nil && impl.name == name { - onTouchStart(sprite) +func (p *SpriteImpl) OnTouchStart__2(sprite SpriteName, onTouchStart func(Sprite)) { + p.OnTouchStart__0(func(s Sprite) { + impl := spriteOf(s) + if impl != nil && impl.name == sprite { + onTouchStart(s) } }) } -func (p *SpriteImpl) OnTouchStart__3(name string, onTouchStart func()) { - p.OnTouchStart__2(name, func(Sprite) { +func (p *SpriteImpl) OnTouchStart__3(sprite SpriteName, onTouchStart func()) { + p.OnTouchStart__2(sprite, func(Sprite) { onTouchStart() }) } @@ -691,7 +719,7 @@ func (p *SpriteImpl) IsCloned() bool { // ----------------------------------------------------------------------------- -func (p *SpriteImpl) CostumeName() string { +func (p *SpriteImpl) CostumeName() SpriteCostumeName { return p.getCostumeName() } @@ -699,7 +727,13 @@ func (p *SpriteImpl) CostumeIndex() int { return p.getCostumeIndex() } -func (p *SpriteImpl) SetCostume(costume interface{}) { +// SetCostume func: +// +// SetCostume(costume) or +// SetCostume(index) or +// SetCostume(spx.Next) or +// SetCostume(spx.Prev) +func (p *SpriteImpl) setCostume(costume interface{}) { if debugInstr { log.Println("SetCostume", p.name, costume) } @@ -707,6 +741,22 @@ func (p *SpriteImpl) SetCostume(costume interface{}) { p.defaultCostumeIndex = p.costumeIndex_ } +func (p *SpriteImpl) SetCostume__0(costume SpriteCostumeName) { + p.setCostume(costume) +} + +func (p *SpriteImpl) SetCostume__1(index int) { + p.setCostume(index) +} + +func (p *SpriteImpl) SetCostume__2(index float64) { + p.setCostume(index) +} + +func (p *SpriteImpl) SetCostume__3(action switchAction) { + p.setCostume(action) +} + func (p *SpriteImpl) NextCostume() { if debugInstr { log.Println("NextCostume", p.name) @@ -739,7 +789,7 @@ func (p *SpriteImpl) getFromAnToForAniFrames(from interface{}, to interface{}) ( fromval := 0.0 toval := 0.0 switch v := from.(type) { - case string: + case SpriteCostumeName: fromval = float64(p.findCostume(v)) if fromval < 0 { log.Panicf("findCostume %s failed", v) @@ -749,7 +799,7 @@ func (p *SpriteImpl) getFromAnToForAniFrames(from interface{}, to interface{}) ( } switch v := to.(type) { - case string: + case SpriteCostumeName: toval = float64(p.findCostume(v)) if toval < 0 { log.Panicf("findCostume %s failed", v) @@ -771,10 +821,10 @@ func (p *SpriteImpl) getStateAnimName(stateName string) string { func lerp(a float64, b float64, progress float64) float64 { return a + (b-a)*progress } -func (p *SpriteImpl) goAnimate(name string, ani *aniConfig) { +func (p *SpriteImpl) goAnimate(name SpriteAnimationName, ani *aniConfig) { p.goAnimateInternal(name, ani, true) } -func (p *SpriteImpl) goAnimateInternal(name string, ani *aniConfig, isBlocking bool) { +func (p *SpriteImpl) goAnimateInternal(name SpriteAnimationName, ani *aniConfig, isBlocking bool) { if p.lastAnim != nil { p.isWaitingStopAnim = true p.lastAnim.Stop() @@ -947,7 +997,7 @@ func (p *SpriteImpl) goAnimateInternal(name string, ani *aniConfig, isBlocking b } } -func (p *SpriteImpl) Animate(name string) { +func (p *SpriteImpl) Animate(name SpriteAnimationName) { if debugInstr { log.Println("==> Animation", name) } @@ -964,23 +1014,31 @@ func (p *SpriteImpl) Ask(msg interface{}) { panic("todo") } -func (p *SpriteImpl) Say(msg interface{}, secs ...float64) { +func (p *SpriteImpl) Say__0(msg interface{}) { + p.Say__1(msg, 0) +} + +func (p *SpriteImpl) Say__1(msg interface{}, secs float64) { if debugInstr { log.Println("Say", p.name, msg, secs) } p.sayOrThink(msg, styleSay) - if secs != nil { - p.waitStopSay(secs[0]) + if secs > 0 { + p.waitStopSay(secs) } } -func (p *SpriteImpl) Think(msg interface{}, secs ...float64) { +func (p *SpriteImpl) Think__0(msg interface{}) { + p.Think__1(msg, 0) +} + +func (p *SpriteImpl) Think__1(msg interface{}, secs float64) { if debugInstr { log.Println("Think", p.name, msg, secs) } p.sayOrThink(msg, styleThink) - if secs != nil { - p.waitStopSay(secs[0]) + if secs > 0 { + p.waitStopSay(secs) } } @@ -993,16 +1051,20 @@ func (p *SpriteImpl) Quote__0(message string) { } func (p *SpriteImpl) Quote__1(message string, secs float64) { - p.Quote__2(message, "", secs) + p.Quote__3(message, "", secs) } -func (p *SpriteImpl) Quote__2(message, description string, secs ...float64) { +func (p *SpriteImpl) Quote__2(message, description string) { + p.Quote__3(message, description, 0) +} + +func (p *SpriteImpl) Quote__3(message, description string, secs float64) { if debugInstr { log.Println("Quote", p.name, message, description, secs) } p.quote_(message, description) - if secs != nil { - p.waitStopQuote(secs[0]) + if secs > 0 { + p.waitStopQuote(secs) } } @@ -1015,10 +1077,9 @@ func (p *SpriteImpl) getXY() (x, y float64) { // DistanceTo func: // // DistanceTo(sprite) -// DistanceTo(spriteName) // DistanceTo(spx.Mouse) // DistanceTo(spx.Random) -func (p *SpriteImpl) DistanceTo(obj interface{}) float64 { +func (p *SpriteImpl) distanceTo(obj interface{}) float64 { x, y := p.x, p.y x2, y2 := p.g.objectPos(obj) x -= x2 @@ -1026,6 +1087,22 @@ func (p *SpriteImpl) DistanceTo(obj interface{}) float64 { return math.Sqrt(x*x + y*y) } +func (p *SpriteImpl) DistanceTo__0(sprite Sprite) float64 { + return p.distanceTo(sprite) +} + +func (p *SpriteImpl) DistanceTo__1(sprite SpriteName) float64 { + return p.distanceTo(sprite) +} + +func (p *SpriteImpl) DistanceTo__2(obj specialObj) float64 { + return p.distanceTo(obj) +} + +func (p *SpriteImpl) DistanceTo__3(pos Pos) float64 { + return p.distanceTo(pos) +} + func (p *SpriteImpl) doMoveTo(x, y float64) { p.doMoveToForAnim(x, y, nil) } @@ -1068,18 +1145,18 @@ func (p *SpriteImpl) Step__1(step int) { p.Step__0(float64(step)) } -func (p *SpriteImpl) Step__2(step float64, animname string) { +func (p *SpriteImpl) Step__2(step float64, animation SpriteAnimationName) { if debugInstr { log.Println("Step", p.name, step) } - if ani, ok := p.animations[animname]; ok { + if ani, ok := p.animations[animation]; ok { anicopy := *ani anicopy.From = 0 anicopy.To = step anicopy.AniType = aniTypeMove anicopy.Duration = math.Abs(step) * ani.StepDuration - p.goAnimate(animname, &anicopy) + p.goAnimate(animation, &anicopy) return } p.goMoveForward(step) @@ -1107,10 +1184,9 @@ func (p *SpriteImpl) playDefaultAnim() { // Goto func: // // Goto(sprite) -// Goto(spriteName) // Goto(spx.Mouse) // Goto(spx.Random) -func (p *SpriteImpl) Goto(obj interface{}) { +func (p *SpriteImpl) goGoto(obj interface{}) { if debugInstr { log.Println("Goto", p.name, obj) } @@ -1118,6 +1194,18 @@ func (p *SpriteImpl) Goto(obj interface{}) { p.SetXYpos(x, y) } +func (p *SpriteImpl) Goto__0(sprite Sprite) { + p.goGoto(sprite) +} + +func (p *SpriteImpl) Goto__1(sprite SpriteName) { + p.goGoto(sprite) +} + +func (p *SpriteImpl) Goto__2(obj specialObj) { + p.goGoto(obj) +} + func (p *SpriteImpl) Glide__0(x, y float64, secs float64) { if debugInstr { log.Println("Glide", p.name, x, y, secs) @@ -1134,7 +1222,7 @@ func (p *SpriteImpl) Glide__0(x, y float64, secs float64) { p.goAnimate(animName, ani) } -func (p *SpriteImpl) Glide__1(obj interface{}, secs float64) { +func (p *SpriteImpl) goGlide(obj interface{}, secs float64) { if debugInstr { log.Println("Glide", obj, secs) } @@ -1142,6 +1230,22 @@ func (p *SpriteImpl) Glide__1(obj interface{}, secs float64) { p.Glide__0(x, y, secs) } +func (p *SpriteImpl) Glide__1(sprite Sprite, secs float64) { + p.goGlide(sprite, secs) +} + +func (p *SpriteImpl) Glide__2(sprite SpriteName, secs float64) { + p.goGlide(sprite, secs) +} + +func (p *SpriteImpl) Glide__3(obj specialObj, secs float64) { + p.goGlide(obj, secs) +} + +func (p *SpriteImpl) Glide__4(pos Pos, secs float64) { + p.goGlide(pos, secs) +} + func (p *SpriteImpl) SetXYpos(x, y float64) { p.doMoveTo(x, y) } @@ -1211,7 +1315,7 @@ func (p *SpriteImpl) Heading() float64 { // Turn(spx.Left) // Turn(spx.Right) // Turn(ti *spx.TurningInfo) -func (p *SpriteImpl) Turn(val interface{}) { +func (p *SpriteImpl) turn(val interface{}) { var delta float64 switch v := val.(type) { //case specialDir: @@ -1240,17 +1344,28 @@ func (p *SpriteImpl) Turn(val interface{}) { } } +func (p *SpriteImpl) Turn__0(degree float64) { + p.turn(degree) +} + +func (p *SpriteImpl) Turn__1(dir specialDir) { + p.turn(dir) +} + +func (p *SpriteImpl) Turn__2(ti *TurningInfo) { + p.turn(ti) +} + // TurnTo func: // // TurnTo(sprite) -// TurnTo(spriteName) // TurnTo(spx.Mouse) // TurnTo(degree) // TurnTo(spx.Left) // TurnTo(spx.Right) // TurnTo(spx.Up) // TurnTo(spx.Down) -func (p *SpriteImpl) TurnTo(obj interface{}) { +func (p *SpriteImpl) turnTo(obj interface{}) { var angle float64 switch v := obj.(type) { //case specialDir: @@ -1290,6 +1405,26 @@ func (p *SpriteImpl) TurnTo(obj interface{}) { } } +func (p *SpriteImpl) TurnTo__0(sprite Sprite) { + p.turnTo(sprite) +} + +func (p *SpriteImpl) TurnTo__1(sprite SpriteName) { + p.turnTo(sprite) +} + +func (p *SpriteImpl) TurnTo__2(obj specialObj) { + p.turnTo(obj) +} + +func (p *SpriteImpl) TurnTo__3(degree float64) { + p.turnTo(degree) +} + +func (p *SpriteImpl) TurnTo__4(dir specialDir) { + p.turnTo(dir) +} + func (p *SpriteImpl) SetHeading(dir float64) { p.setDirection(dir, false) } @@ -1397,7 +1532,6 @@ func (p *SpriteImpl) TouchingColor(color Color) bool { // Touching func: // -// Touching(spriteName) // Touching(sprite) // Touching(spx.Mouse) // Touching(spx.Edge) @@ -1405,12 +1539,12 @@ func (p *SpriteImpl) TouchingColor(color Color) bool { // Touching(spx.EdgeTop) // Touching(spx.EdgeRight) // Touching(spx.EdgeBottom) -func (p *SpriteImpl) Touching(obj interface{}) bool { +func (p *SpriteImpl) touching(obj interface{}) bool { if !p.isVisible || p.isDying { return false } switch v := obj.(type) { - case string: + case SpriteName: if o := p.g.touchingSpriteBy(p, v); o != nil { return true } @@ -1428,6 +1562,18 @@ func (p *SpriteImpl) Touching(obj interface{}) bool { panic("Touching: unexpected input") } +func (p *SpriteImpl) Touching__0(sprite SpriteName) bool { + return p.touching(sprite) +} + +func (p *SpriteImpl) Touching__1(sprite Sprite) bool { + return p.touching(sprite) +} + +func (p *SpriteImpl) Touching__2(obj specialObj) bool { + return p.touching(obj) +} + func touchingSprite(dst, src *SpriteImpl) bool { if !src.isVisible || src.isDying { return false diff --git a/widget.go b/widget.go index 491655a0..500a4737 100644 --- a/widget.go +++ b/widget.go @@ -1,7 +1,7 @@ package spx type Widget interface { - GetName() string + GetName() WidgetName Visible() bool Show() Hide() @@ -19,3 +19,5 @@ type Widget interface { SetSize(size float64) ChangeSize(delta float64) } + +type WidgetName = string