package main

import (
	"github.com/mhaya"
	mhayaCron "github.com/mhaya/components/cron"
	mhayaGops "github.com/mhaya/components/gops"
	mhayaMongo "github.com/mhaya/components/mongo"
	mhayaSnowflake "github.com/mhaya/extend/snowflake"
	cstring "github.com/mhaya/extend/string"
	mhayaUtils "github.com/mhaya/extend/utils"
	checkCenter "github.com/mhaya/game/game_cluster/internal/component/check_center"
	"github.com/mhaya/game/game_cluster/internal/data"
	"github.com/mhaya/game/game_cluster/internal/mdb"
	"github.com/mhaya/game/game_cluster/nodes/game/module/player"
)

func main() {
	nodeId := "10001"
	if mhayaUtils.IsNumeric(nodeId) == false {
		panic("node parameter must is number.")
	}

	// snowflake global id
	serverId, _ := cstring.ToInt64(nodeId)
	mhayaSnowflake.SetDefaultNode(serverId)

	// 配置mhaya引擎
	app := mhaya.Configure("./config/profile-gc.json", nodeId, false, mhaya.Cluster)

	// diagnose
	app.Register(mhayaGops.New())
	// 注册调度组件
	app.Register(mhayaCron.New())
	// 注册数据配置组件
	app.Register(data.New())
	// 注册检测中心节点组件，确认中心节点启动后，再启动当前节点
	app.Register(checkCenter.New())
	// 注册db组件
	app.Register(mhayaMongo.NewComponent())

	app.AddActors(
		&player.ActorPlayers{Name: nodeId},
		&player.ActorAvatars{Name: nodeId},
		&mdb.ActorDB{Name: nodeId},
	)

	app.Startup()
}
