Skip to content

Commit

Permalink
Fix issue 316 Type definition for sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
qlli committed Oct 17, 2024
1 parent 1c08777 commit ec22f36
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 233 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.DS_Store
sprite.txt
game.txt
gop.mod
go.work
go.json
gop.json
Expand Down
6 changes: 3 additions & 3 deletions camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (c *Camera) On(obj interface{}) {
return
}
obj = sp
case *Sprite:
case *SpriteImpl:
case nil:
case Spriter:
case Sprite:
obj = spriteOf(v)
case specialObj:
if v != Mouse {
Expand All @@ -85,7 +85,7 @@ func (c *Camera) On(obj interface{}) {

func (c *Camera) updateOnObj() {
switch v := c.on_.(type) {
case *Sprite:
case *SpriteImpl:
cx, cy := v.getXY()
c.freecamera.MoveTo(cx, cy)
case nil:
Expand Down
29 changes: 21 additions & 8 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,30 +159,30 @@ func (p *eventSinkMgr) doWhenClick(this threadObj) {
})
}

func (p *eventSinkMgr) doWhenTouchStart(this threadObj, obj *Sprite) {
func (p *eventSinkMgr) doWhenTouchStart(this threadObj, obj *SpriteImpl) {
p.allWhenTouchStart.asyncCall(false, this, func(ev *eventSink) {
if debugEvent {
log.Println("===> onTouchStart", nameOf(this), obj.name)
}
ev.sink.(func(*Sprite))(obj)
ev.sink.(func(Sprite))(obj.sprite)
})
}

func (p *eventSinkMgr) doWhenTouching(this threadObj, obj *Sprite) {
func (p *eventSinkMgr) doWhenTouching(this threadObj, obj *SpriteImpl) {
p.allWhenTouching.asyncCall(false, this, func(ev *eventSink) {
if debugEvent {
log.Println("==> onTouching", nameOf(this), obj.name)
}
ev.sink.(func(*Sprite))(obj)
ev.sink.(func(Sprite))(obj.sprite)
})
}

func (p *eventSinkMgr) doWhenTouchEnd(this threadObj, obj *Sprite) {
func (p *eventSinkMgr) doWhenTouchEnd(this threadObj, obj *SpriteImpl) {
p.allWhenTouchEnd.asyncCall(false, this, func(ev *eventSink) {
if debugEvent {
log.Println("===> onTouchEnd", nameOf(this), obj.name)
}
ev.sink.(func(*Sprite))(obj)
ev.sink.(func(Sprite))(obj.sprite)
})
}

Expand Down Expand Up @@ -220,14 +220,27 @@ func (p *eventSinkMgr) doWhenBackdropChanged(name string, wait bool) {
}

// -------------------------------------------------------------------------------------
type IEventSinks interface {
OnAnyKey(onKey func(key Key))
OnBackdrop__0(onBackdrop func(name string))
OnBackdrop__1(name string, onBackdrop func())
OnClick(onClick func())
OnKey__0(key Key, onKey func())
OnKey__1(keys []Key, onKey func(Key))
OnKey__2(keys []Key, onKey func())
OnMsg__0(onMsg func(msg string, data interface{}))
OnMsg__1(msg string, onMsg func())
OnStart(onStart func())
Stop(kind StopKind)
}

type eventSinks struct {
*eventSinkMgr
pthis threadObj
}

func nameOf(this interface{}) string {
if spr, ok := this.(*Sprite); ok {
if spr, ok := this.(*SpriteImpl); ok {
return spr.name
}
if _, ok := this.(*Game); ok {
Expand Down Expand Up @@ -423,7 +436,7 @@ func isGame(obj threadObj) bool {
}

func isSprite(obj threadObj) bool {
_, ok := obj.(*Sprite)
_, ok := obj.(*SpriteImpl)
return ok
}

Expand Down
Loading

0 comments on commit ec22f36

Please sign in to comment.