This commit is contained in:
xzb 2023-09-27 10:08:48 +08:00
commit 6edff67117
2 changed files with 11 additions and 17 deletions

View File

@ -3,7 +3,6 @@ package entities
import (
"time"
"github.com/yohamta/donburi/component"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/repository"
@ -44,13 +43,7 @@ func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout) []*ec
if len(turnout.RelayGroups()) == 0 {
continue
}
var components []component.IComponentType
components = append(components, system.EntityIdentityComponent)
components = append(components, system.Switch2jZdj9StateComponent)
entry := world.Create(components...)
entries = append(entries, entry)
system.EntityIdentityComponent.Set(entry, &system.EntityIdentity{Id: turnout.Id()})
system.Switch2jZdj9StateComponent.Set(entry, system.NewSwitch2jZdj9State())
entries = append(entries, CreateSwitch2jzdj9Entity(world, turnout.Id()))
}
return entries
}
@ -58,22 +51,22 @@ func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout) []*ec
func TurnToNormal(worldId ecs.WorldId, turnoutId string) {
sim := simulation.FindSimulation(worldId)
system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true)
system.Switch2jZdj9DriveFc(sim.World(), turnoutId, true)
system.Switch2jZdj9DriveDc(sim.World(), turnoutId, true)
go func() {
<-time.After(1 * time.Second)
<-time.After(5 * time.Second)
system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false)
system.Switch2jZdj9DriveFc(sim.World(), turnoutId, false)
system.Switch2jZdj9DriveDc(sim.World(), turnoutId, false)
}()
}
func TurnToReverse(worldId ecs.WorldId, turnoutId string) {
sim := simulation.FindSimulation(worldId)
system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true)
system.Switch2jZdj9DriveDc(sim.World(), turnoutId, true)
system.Switch2jZdj9DriveFc(sim.World(), turnoutId, true)
go func() {
<-time.After(1 * time.Second)
<-time.After(5 * time.Second)
system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false)
system.Switch2jZdj9DriveDc(sim.World(), turnoutId, false)
system.Switch2jZdj9DriveFc(sim.World(), turnoutId, false)
}()
}

View File

@ -1,25 +1,26 @@
package world
import (
"time"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/entities"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/simulation"
"joylink.club/rtsssimulation/system"
"time"
)
func CreateSimulation(repo *repository.Repository) ecs.WorldId {
var systems []ecs.ISystem
wc := &WorldConfig{
Systems: systems,
Systems: []ecs.ISystem{system.NewTimerSystem(), system.NewPercentageMovableSystem(), system.NewSwitch2jZdj9System(), system.NewRelaySystem()},
Tick: 200,
InitTime: time.Now(),
}
w := InitializeWorld(wc)
simulation.CreateSimulation(repo, w)
//添加实体
entities.CreateSystemTimerEntity(w, wc.InitTime)
entities.CreateTurnoutEntries(w, repo.TurnoutList())
entities.CreateRelayEntries(w, repo.RelayList())
//初始化组件