58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package entity
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/repository"
|
|
"strings"
|
|
)
|
|
|
|
func LoadMkx(w ecs.World) error {
|
|
data := GetWorldData(w)
|
|
mkxs := data.Repo.MkxList()
|
|
for _, mkx := range mkxs {
|
|
entry := NewMkxEntry(w, mkx.Id(), data)
|
|
loadMkxCircuit(w, entry, mkx, data.EntityMap)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func loadMkxCircuit(world ecs.World, entry *ecs.Entry, mkx *repository.Mkx, entryMap map[string]*ecs.Entry) {
|
|
circuit := &component.MkxCircuit{}
|
|
for _, group := range mkx.ComponentGroups() {
|
|
for _, ec := range group.Components() {
|
|
relay := ec.(*repository.Relay)
|
|
if strings.Contains(ec.Code(), "PCBJ") {
|
|
circuit.Pcbj = NewRelayEntity(world, relay, entryMap)
|
|
} else if strings.Contains(ec.Code(), "POBJ") {
|
|
circuit.Pobj = NewRelayEntity(world, relay, entryMap)
|
|
} else if strings.Contains(ec.Code(), "PABJ") {
|
|
circuit.Pabj = NewRelayEntity(world, relay, entryMap)
|
|
}
|
|
}
|
|
for i := 0; i < 3; i++ {
|
|
//NewRelayEntity()
|
|
circuit.PcbList = append(circuit.PcbList)
|
|
}
|
|
}
|
|
component.MkxCircuitType.Set(entry, circuit)
|
|
}
|
|
|
|
func NewMkxEntry(world ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
|
|
entry, ok := worldData.EntityMap[uid]
|
|
if !ok {
|
|
psd := world.Entry(world.Create(component.MkxTag, component.UidType, component.MkxCircuitType))
|
|
component.UidType.SetValue(psd, component.Uid{Id: uid})
|
|
worldData.EntityMap[uid] = psd
|
|
}
|
|
return entry
|
|
}
|
|
|
|
//func NewMkxBox(world ecs.World) *ecs.Entry {
|
|
// entry := world.Entry(world.Create(component.MkxBoxType))
|
|
// component.MkxBox{
|
|
// Btn: NewButtonEntity(),
|
|
// MkxplBtn: nil,
|
|
// }
|
|
//}
|