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 14, 2024
1 parent 2e78093 commit bf70f90
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 205 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
21 changes: 17 additions & 4 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ func (p *eventSinkMgr) doWhenClick(this threadObj) {
})
}

func (p *eventSinkMgr) doWhenTouched(this threadObj, obj *Sprite) {
func (p *eventSinkMgr) doWhenTouched(this threadObj, obj *SpriteImpl) {
p.allWhenTouched.asyncCall(false, this, func(ev *eventSink) {
if debugEvent {
log.Println("==> onTouched", nameOf(this), obj.name)
}
ev.sink.(func(*Sprite))(obj)
ev.sink.(func(interface{}))(obj)
})
}

Expand Down Expand Up @@ -196,14 +196,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 @@ -399,7 +412,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 bf70f90

Please sign in to comment.