61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package component
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component/component_proto"
|
|
"joylink.club/rtsssimulation/consts"
|
|
)
|
|
|
|
// 唯一ID组件
|
|
type Uid struct {
|
|
Id string
|
|
}
|
|
|
|
var UidType = ecs.NewComponentType[Uid]()
|
|
|
|
// 两个稳态位置转换组件
|
|
// type TwoPositionTransform struct {
|
|
// Pos int // 当前位置百分比,[0, 10000],两位小数
|
|
// Speed int
|
|
// }
|
|
|
|
type TwoPositionTransform struct {
|
|
component_proto.TwoPositionTransform
|
|
}
|
|
|
|
// 当前位置百分比值
|
|
func (tp *TwoPositionTransform) Percentage() float32 {
|
|
return float32(tp.Pos) / consts.TwoPosMax
|
|
}
|
|
|
|
var TwoPositionTransformType = ecs.NewComponentType[TwoPositionTransform]()
|
|
|
|
// 计算两位置动作的平均速度
|
|
// 总时间t和tick的单位都应该是ms
|
|
func CalculateTwoPositionAvgSpeed(t int, tick int) int32 {
|
|
return int32(consts.TwoPosMax / (t / tick))
|
|
}
|
|
|
|
// 仅有两状态的组件
|
|
type BitState struct {
|
|
Val bool
|
|
}
|
|
|
|
var BitStateType = ecs.NewComponentType[BitState]()
|
|
|
|
// 倒数/倒计时组件
|
|
type CounterDown struct {
|
|
Val int // 当前值
|
|
Step int // 步长
|
|
}
|
|
|
|
var CounterDownType = ecs.NewComponentType[CounterDown]()
|
|
|
|
// 计数/计时组件
|
|
type Counter struct {
|
|
Val int // 当前值
|
|
Step int // 步长
|
|
}
|
|
|
|
var CounterType = ecs.NewComponentType[Counter]()
|