2023-09-22 18:33:01 +08:00
|
|
|
|
package component
|
|
|
|
|
|
2023-09-26 18:06:15 +08:00
|
|
|
|
import (
|
|
|
|
|
"joylink.club/ecs"
|
2024-01-02 18:22:28 +08:00
|
|
|
|
"joylink.club/rtsssimulation/component/component_data"
|
2023-09-26 18:06:15 +08:00
|
|
|
|
"joylink.club/rtsssimulation/consts"
|
2024-01-10 14:06:00 +08:00
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-09-26 18:06:15 +08:00
|
|
|
|
)
|
2023-09-22 18:33:01 +08:00
|
|
|
|
|
2024-01-02 18:22:28 +08:00
|
|
|
|
var (
|
|
|
|
|
UidType = ecs.NewComponentType[Uid]()
|
|
|
|
|
// 固定位置转换组件类型
|
|
|
|
|
FixedPositionTransformType = ecs.NewComponentType[FixedPositionTransform]()
|
|
|
|
|
// 电机状态组件类型
|
2024-01-10 10:57:47 +08:00
|
|
|
|
MotorStateType = ecs.NewComponentType[component_data.MotorState]()
|
2024-01-02 18:22:28 +08:00
|
|
|
|
BitStateType = ecs.NewComponentType[BitState]()
|
|
|
|
|
)
|
2023-12-29 17:48:57 +08:00
|
|
|
|
|
2024-02-06 10:49:46 +08:00
|
|
|
|
/*type Bypass struct {
|
2024-02-04 18:22:52 +08:00
|
|
|
|
BypassEnable bool // 摁钮,钥匙 是否旁路
|
|
|
|
|
OldVal bool //摁钮旁路旧值
|
2024-02-06 10:49:46 +08:00
|
|
|
|
}*/
|
2024-02-04 18:22:52 +08:00
|
|
|
|
|
2023-09-27 18:39:18 +08:00
|
|
|
|
// 唯一ID组件
|
|
|
|
|
type Uid struct {
|
|
|
|
|
Id string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 两个稳态位置转换组件
|
2023-10-09 11:17:25 +08:00
|
|
|
|
// type TwoPositionTransform struct {
|
|
|
|
|
// Pos int // 当前位置百分比,[0, 10000],两位小数
|
|
|
|
|
// Speed int
|
|
|
|
|
// }
|
|
|
|
|
|
2023-12-29 17:48:57 +08:00
|
|
|
|
type FixedPositionTransform struct {
|
2024-01-10 10:57:47 +08:00
|
|
|
|
component_data.FixedPositionTransform
|
2023-09-22 18:33:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 18:39:18 +08:00
|
|
|
|
// 当前位置百分比值
|
2023-12-29 17:48:57 +08:00
|
|
|
|
func (tp *FixedPositionTransform) Percentage() float32 {
|
2023-09-26 18:06:15 +08:00
|
|
|
|
return float32(tp.Pos) / consts.TwoPosMax
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算两位置动作的平均速度
|
|
|
|
|
// 总时间t和tick的单位都应该是ms
|
2024-01-02 18:22:28 +08:00
|
|
|
|
// t - 总时间,tick - 执行间隔
|
2023-10-09 11:17:25 +08:00
|
|
|
|
func CalculateTwoPositionAvgSpeed(t int, tick int) int32 {
|
|
|
|
|
return int32(consts.TwoPosMax / (t / tick))
|
2023-09-26 18:06:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 18:33:01 +08:00
|
|
|
|
// 仅有两状态的组件
|
|
|
|
|
type BitState struct {
|
2024-02-06 10:49:46 +08:00
|
|
|
|
//Bypass
|
2023-09-22 18:33:01 +08:00
|
|
|
|
Val bool
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 18:06:15 +08:00
|
|
|
|
// 倒数/倒计时组件
|
|
|
|
|
type CounterDown struct {
|
|
|
|
|
Val int // 当前值
|
|
|
|
|
Step int // 步长
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var CounterDownType = ecs.NewComponentType[CounterDown]()
|
|
|
|
|
|
|
|
|
|
// 计数/计时组件
|
|
|
|
|
type Counter struct {
|
|
|
|
|
Val int // 当前值
|
|
|
|
|
Step int // 步长
|
2023-09-22 18:33:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 18:06:15 +08:00
|
|
|
|
var CounterType = ecs.NewComponentType[Counter]()
|
2024-01-08 17:45:15 +08:00
|
|
|
|
|
2024-01-10 11:12:19 +08:00
|
|
|
|
var LinkPositionType = ecs.NewComponentType[component_data.LinkPosition]()
|
2024-01-10 14:06:00 +08:00
|
|
|
|
var KmType = ecs.NewComponentType[proto.Kilometer]()
|