-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 修复 activity 类型转换错误问题,增加案例目录 activity/internal/example
- Loading branch information
1 parent
605a308
commit 3a33947
Showing
6 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package activities | ||
|
||
import ( | ||
"github.com/kercylan98/minotaur/game/activity" | ||
"github.com/kercylan98/minotaur/game/activity/internal/example/types" | ||
"github.com/kercylan98/minotaur/utils/super" | ||
"time" | ||
) | ||
|
||
var ( | ||
DemoActivity = activity.DefineEntityDataActivity[int, int, string, *types.DemoActivityData](1).InitializeEntityData(func(activityId int, entityId string, data *activity.EntityDataMeta[*types.DemoActivityData]) { | ||
// 模拟数据库加载 | ||
_ = super.UnmarshalJSON([]byte(`{"last_new_day": "2021-01-01 00:00:00", "data": {"login_num": 3}}`), data) | ||
}) | ||
) | ||
|
||
func init() { | ||
// 模拟配置加载活动 | ||
if err := activity.LoadOrRefreshActivity(1, 1, activity.NewOptions(). | ||
WithStartTime(time.Now().Add(time.Second*3)), | ||
); err != nil { | ||
panic(err) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
game/activity/internal/example/activities/demoactivity/demoactivity.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package demoactivity | ||
|
||
import ( | ||
"github.com/kercylan98/minotaur/game/activity" | ||
"github.com/kercylan98/minotaur/game/activity/internal/example/activities" | ||
"github.com/kercylan98/minotaur/utils/log" | ||
) | ||
|
||
func init() { | ||
activity.RegStartedEvent(1, onActivityStart) | ||
} | ||
|
||
func onActivityStart(id int) { | ||
log.Info("activity start", log.Int("id", id), log.Any("entity", activities.DemoActivity.GetEntityData(id, "demo_entity"))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
_ "github.com/kercylan98/minotaur/game/activity/internal/example/activities/demoactivity" | ||
"time" | ||
) | ||
|
||
func main() { | ||
time.Sleep(time.Second * 5) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package types | ||
|
||
type DemoActivityData struct { | ||
LoginNum int `json:"login_num"` // 登录次数 | ||
} |