Skip to content

Commit

Permalink
Merge pull request #347 from goplus/main
Browse files Browse the repository at this point in the history
Sync main to dev
  • Loading branch information
nighca authored Oct 21, 2024
2 parents 8285bd8 + 6ee4234 commit 8ec742e
Show file tree
Hide file tree
Showing 34 changed files with 1,502 additions and 1,057 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ How to show the `score` on the stage? You don't need write code, just add a `sta
{
"zorder": [
{
"type": "stageMonitor",
"type": "monitor",
"name": "dragon",
"size": 1,
"target": "Dragon",
"val": "getVar:score",
"color": 15629590,
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
26 changes: 18 additions & 8 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,22 @@ type actionConfig struct {
}

type aniConfig struct {
Duration float64 `json:"duration"`
Fps float64 `json:"fps"`
From interface{} `json:"from"`
To interface{} `json:"to"`
AniType aniTypeEnum `json:"anitype"`
OnStart *actionConfig `json:"onStart"` //start
OnPlay *actionConfig `json:"onPlay"` //play
IsLoop bool `json:"isLoop"`
Duration float64 `json:"duration"`
Fps float64 `json:"fps"`
From interface{} `json:"from"`
To interface{} `json:"to"`
FrameFrom string `json:"frameFrom"`
FrameTo string `json:"frameTo"`
FrameFps int `json:"frameFps"`
StepDuration float64 `json:"stepDuration"`
TurnToDuration float64 `json:"turnToDuration"`

AniType aniTypeEnum `json:"anitype"`
OnStart *actionConfig `json:"onStart"` //start
OnPlay *actionConfig `json:"onPlay"` //play
IsLoop bool `json:"isLoop"`
IsKeepOnStop bool `json:"isKeepOnStop"` //After finishing playback, it stays on the last frame and does not need to switch to the default animation

//OnEnd *actionConfig `json:"onEnd"` //stop
}

Expand All @@ -235,6 +243,8 @@ type spriteConfig struct {
Visible bool `json:"visible"`
IsDraggable bool `json:"isDraggable"`
Pivot math32.Vector2 `json:"pivot"`
DefaultAnimation string `json:"defaultAnimation"`
AnimBindings map[string]string `json:"animBindings"`
}

func (p *spriteConfig) getCostumeIndex() int {
Expand Down
55 changes: 46 additions & 9 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ type eventSinkMgr struct {
allWhenIReceive *eventSink
allWhenBackdropChanged *eventSink
allWhenCloned *eventSink
allWhenTouched *eventSink
allWhenTouchStart *eventSink
allWhenTouching *eventSink
allWhenTouchEnd *eventSink
allWhenClick *eventSink
allWhenMoving *eventSink
allWhenTurning *eventSink
Expand All @@ -107,7 +109,9 @@ func (p *eventSinkMgr) reset() {
p.allWhenIReceive = nil
p.allWhenBackdropChanged = nil
p.allWhenCloned = nil
p.allWhenTouched = nil
p.allWhenTouchStart = nil
p.allWhenTouching = nil
p.allWhenTouchEnd = nil
p.allWhenClick = nil
p.allWhenMoving = nil
p.allWhenTurning = nil
Expand All @@ -120,7 +124,9 @@ func (p *eventSinkMgr) doDeleteClone(this interface{}) {
p.allWhenIReceive = p.allWhenIReceive.doDeleteClone(this)
p.allWhenBackdropChanged = p.allWhenBackdropChanged.doDeleteClone(this)
p.allWhenCloned = p.allWhenCloned.doDeleteClone(this)
p.allWhenTouched = p.allWhenTouched.doDeleteClone(this)
p.allWhenTouchStart = p.allWhenTouchStart.doDeleteClone(this)
p.allWhenTouching = p.allWhenTouching.doDeleteClone(this)
p.allWhenTouchEnd = p.allWhenTouchEnd.doDeleteClone(this)
p.allWhenClick = p.allWhenClick.doDeleteClone(this)
p.allWhenMoving = p.allWhenMoving.doDeleteClone(this)
p.allWhenTurning = p.allWhenTurning.doDeleteClone(this)
Expand Down Expand Up @@ -153,12 +159,30 @@ func (p *eventSinkMgr) doWhenClick(this threadObj) {
})
}

func (p *eventSinkMgr) doWhenTouched(this threadObj, obj *Sprite) {
p.allWhenTouched.asyncCall(false, this, func(ev *eventSink) {
func (p *eventSinkMgr) doWhenTouchStart(this threadObj, obj *SpriteImpl) {
p.allWhenTouchStart.asyncCall(false, this, func(ev *eventSink) {
if debugEvent {
log.Println("==> onTouched", nameOf(this), obj.name)
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 *SpriteImpl) {
p.allWhenTouching.asyncCall(false, this, func(ev *eventSink) {
if debugEvent {
log.Println("==> onTouching", nameOf(this), obj.name)
}
ev.sink.(func(Sprite))(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.sprite)
})
}

Expand Down Expand Up @@ -196,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 @@ -399,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 8ec742e

Please sign in to comment.