From 9d37273d91fb05f6f2e91e6f30945878384450f6 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 13 Sep 2023 10:29:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/button.go | 15 ------ jl-ecs-go | 2 +- system/button_system.go | 104 ---------------------------------------- 3 files changed, 1 insertion(+), 120 deletions(-) delete mode 100644 components/button.go delete mode 100644 system/button_system.go diff --git a/components/button.go b/components/button.go deleted file mode 100644 index 54ec318..0000000 --- a/components/button.go +++ /dev/null @@ -1,15 +0,0 @@ -package components - -import ( - "joylink.club/ecs" - "joylink.club/rtsssimulation/components/cstate" -) - -// 按钮状态组件 -var ButtonStateComponent = ecs.NewComponentType[cstate.ButtonState]() - -// 按钮操作组件 -var ButtonPressOperatingComponent = ecs.NewComponentType[cstate.ButtonPressOperating]() - -// 按钮确认组件 -var ButtonConfirmOperatingComponent = ecs.NewComponentType[cstate.ButtonConfirmOperating]() diff --git a/jl-ecs-go b/jl-ecs-go index c3b9d96..8ffea35 160000 --- a/jl-ecs-go +++ b/jl-ecs-go @@ -1 +1 @@ -Subproject commit c3b9d965c607a2f29e0bdc586aba6851d4f29f13 +Subproject commit 8ffea356da60f2811eed5735c5733c0a24b0fbea diff --git a/system/button_system.go b/system/button_system.go deleted file mode 100644 index 452dd1d..0000000 --- a/system/button_system.go +++ /dev/null @@ -1,104 +0,0 @@ -package system - -import ( - "github.com/yohamta/donburi/filter" - "joylink.club/ecs" - "joylink.club/rtsssimulation/components" -) - -// 按钮系统 -type ButtonSystem struct { -} - -// 按钮组件 -var btnIdCom, btnStaCom, btnPreOperCom, btnConOperCom = components.DeviceIdentityComponent, - components.ButtonStateComponent, components.ButtonPressOperatingComponent, components.ButtonConfirmOperatingComponent - -// 查询 -var btnIdQuery = ecs.NewQuery(filter.Contains(btnIdCom)) -var btnUpdateQuery = ecs.NewQuery(filter.Contains(btnStaCom, btnPreOperCom, btnConOperCom)) - -func NewButtonSystem() *ButtonSystem { - return &ButtonSystem{} -} - -// 按钮操作 -func PressDownAndUpButton(w ecs.World, btnId string, down bool) bool { - buttonEntry := queryButton(w, btnId) - if buttonEntry == nil { - return false - } - t, b := getButtonBaseInfo(btnId) - if !buttonEntry.HasComponent(btnPreOperCom) { // 操作组件 - buttonEntry.AddComponent(btnPreOperCom) - } - preOper := btnPreOperCom.Get(buttonEntry) - preOper.Start, preOper.Down, preOper.NeedConfirm, preOper.OperateTime = true, down, b, t - return true -} - -// 确认操作 -func ConfirmButton(w ecs.World, btnId string, confirm bool) bool { - buttonEntry := queryButton(w, btnId) - if buttonEntry == nil { - return false - } - if !buttonEntry.HasComponent(btnConOperCom) { // 确认组件 - buttonEntry.AddComponent(btnConOperCom) - } - conOper := btnConOperCom.Get(buttonEntry) - conOper.Confirm, conOper.Cancel = confirm, !confirm - return true -} - -// 更新按钮状态 -func (bs *ButtonSystem) Update(w ecs.World) { - btnUpdateQuery.Each(w, func(e *ecs.Entry) { - if e.HasComponent(btnPreOperCom) { - btnPreOper := btnPreOperCom.Get(e) - if btnPreOper.Start { // 按钮开始操作 - if btnPreOper.OperateTime <= 0 { // 按钮操作时间大于0 - btnPreOper.Start, btnPreOper.OperateTime = false, 0 - } else { - btnPreOper.OperateTime -= int64(w.Tick()) - if btnPreOper.NeedConfirm { - conOper := btnConOperCom.Get(e) - if e.HasComponent(btnConOperCom) && (conOper.Cancel || conOper.Confirm) { - if conOper.Confirm { - btnSta := btnStaCom.Get(e) - btnSta.PressDown = btnPreOper.Down - } - btnPreOper.Start, btnPreOper.OperateTime = false, 0 - conOper.Cancel, conOper.Confirm = false, false - e.RemoveComponent(btnPreOperCom) - e.RemoveComponent(btnConOperCom) - } - } else { - btnSta := btnStaCom.Get(e) - btnSta.PressDown = btnPreOper.Down - btnPreOper.Start, btnPreOper.OperateTime = false, 0 - e.RemoveComponent(btnPreOperCom) - } - } - } else { - e.RemoveComponent(btnPreOperCom) - } - } - }) -} - -// 查找按钮 -func queryButton(w ecs.World, btnId string) *ecs.Entry { - var buttonEntry *ecs.Entry = nil - btnIdQuery.Each(w, func(e *ecs.Entry) { - if id := btnIdCom.Get(e).Id; id == btnId { - buttonEntry = e - } - }) - return buttonEntry -} - -// 获取按钮设置信息 -func getButtonBaseInfo(btnId string) (int64, bool) { - return 15, false -}