rts-sim-module/component/common.go

75 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component/component_data"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/repository/model/proto"
)
var (
UidType = ecs.NewComponentType[Uid]()
// 固定位置转换组件类型
FixedPositionTransformType = ecs.NewComponentType[FixedPositionTransform]()
// 电机状态组件类型
MotorStateType = ecs.NewComponentType[component_data.MotorState]()
BitStateType = ecs.NewComponentType[BitState]()
)
type Bypass struct {
BypassEnable bool // 摁钮,钥匙 是否旁路
OldVal bool //摁钮旁路旧值
}
// 唯一ID组件
type Uid struct {
Id string
}
// 两个稳态位置转换组件
// type TwoPositionTransform struct {
// Pos int // 当前位置百分比,[0, 10000],两位小数
// Speed int
// }
type FixedPositionTransform struct {
component_data.FixedPositionTransform
}
// 当前位置百分比值
func (tp *FixedPositionTransform) Percentage() float32 {
return float32(tp.Pos) / consts.TwoPosMax
}
// 计算两位置动作的平均速度
// 总时间t和tick的单位都应该是ms
// t - 总时间tick - 执行间隔
func CalculateTwoPositionAvgSpeed(t int, tick int) int32 {
return int32(consts.TwoPosMax / (t / tick))
}
// 仅有两状态的组件
type BitState struct {
Bypass
Val bool
}
// 倒数/倒计时组件
type CounterDown struct {
Val int // 当前值
Step int // 步长
}
var CounterDownType = ecs.NewComponentType[CounterDown]()
// 计数/计时组件
type Counter struct {
Val int // 当前值
Step int // 步长
}
var CounterType = ecs.NewComponentType[Counter]()
var LinkPositionType = ecs.NewComponentType[component_data.LinkPosition]()
var KmType = ecs.NewComponentType[proto.Kilometer]()