A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D
Pass query matches to commands.insert and commands.remove
SandroMaglione901985dd2f61
diff --git a/src/sim/edits.ts b/src/sim/edits.tsindex 2dee034..8a3581b 100644--- a/src/sim/edits.ts+++ b/src/sim/edits.ts@@ -375,8 +375,8 @@ export const ApplyEdits = Game.System(const row = id === undefined ? undefined : queries.built.get(id)if (!row?.ok || halls.has(owner) || row.value.data.site.present || row.value.data.paused.present === edit.on) breakif (!row.value.data.building.present && !row.value.data.house.present) break- if (edit.on) commands.insert(row.value.entity.id, Game.Command.entry(Paused, {}))- else commands.remove(row.value.entity.id, Paused)+ if (edit.on) commands.insert(row.value.entity, Game.Command.entry(Paused, {}))+ else commands.remove(row.value.entity, Paused)break}case "deliver": {@@ -447,7 +447,7 @@ export const ApplyEdits = Game.System(coins -= up.cost.coinsbegun.add(row.value.entity.id)const owed = amounts(up.cost.materials)- commands.insert(row.value.entity.id, Game.Command.entry(Works, { owed, total: total(owed), done: 0, level: (level + 1) as 1 | 2 }))+ commands.insert(row.value.entity, Game.Command.entry(Works, { owed, total: total(owed), done: 0, level: (level + 1) as 1 | 2 }))const was = (upgradeAt(kind, level)?.title ?? kind.title).toLowerCase()write(resources.chronicle, t, `Works begin on the ${was}: it is to be ${anA(up.title.toLowerCase())}.`)events.toast.emit(`${up.title} · −${up.cost.coins} coins · carriers bring ${costText({ coins: 0, materials: up.cost.materials })}`)diff --git a/src/sim/hazards.ts b/src/sim/hazards.tsindex e8fd25a..ee27971 100644--- a/src/sim/hazards.ts+++ b/src/sim/hazards.ts@@ -184,13 +184,13 @@ export const Hazards = Game.System(const id = fires.nextfires.next += 1fires.fires.push({ id, x: tile.x, y: tile.y, homes: 0, buildings: 0 })- commands.insert(row.entity.id, Game.Command.entry(Burning, { left: risk.fire.burns, fire: id }))+ commands.insert(row.entity, Game.Command.entry(Burning, { left: risk.fire.burns, fire: id }))ignited.set(row.entity.id, id)r.fire = 0news(`Fire on ${where(tile)}!`, tile)}if (h && r.health >= RISK_MAX && !data.sick.present) {- commands.insert(row.entity.id, Game.Command.entry(Sick, { left: risk.health.lasts }))+ commands.insert(row.entity, Game.Command.entry(Sick, { left: risk.health.lasts }))r.health = 0if (sickNow === 0) news(`Sickness on ${where(tile)}: a physician can cure it.`, tile)}@@ -234,7 +234,7 @@ export const Hazards = Game.System(const s = data.sick.get()const left = s.left - RISK_TICKSif (left <= 0) {- commands.remove(entity.id, Sick)+ commands.remove(entity, Sick)continue}data.sick.set({ left })@@ -272,7 +272,7 @@ export const Hazards = Game.System(if (!neighbour) continueconst chance = risk.fire.catches + (risk.fire.spread * neighbour.data.risk.get().fire) / RISK_MAXif (random.next() < chance) {- commands.insert(neighbour.entity.id, Game.Command.entry(Burning, { left: risk.fire.burns, fire: b.fire }))+ commands.insert(neighbour.entity, Game.Command.entry(Burning, { left: risk.fire.burns, fire: b.fire }))ignited.set(neighbour.entity.id, b.fire)}}diff --git a/src/sim/town.ts b/src/sim/town.tsindex fac46df..2a1d360 100644--- a/src/sim/town.ts+++ b/src/sim/town.ts@@ -98,7 +98,7 @@ export const Households = Game.System(if (tier <= h.tier || tier <= built) next.tier = tierelse if (pay(home.tiers[tier].rise)) {next.tier = tier- commands.insert(entity.id, Game.Command.entry(Rebuilt, { tier: tier as 2 | 3 }))+ commands.insert(entity, Game.Command.entry(Rebuilt, { tier: tier as 2 | 3 }))}const well = connected(grid, tile) ? capacity(next, approval, desirability, rules, rateOf(policy, next.tier)) : 0const cap = data.sick.present ? Math.floor(well * risk.health.sickly) : welldiff --git a/src/sim/walkers.ts b/src/sim/walkers.tsindex f38c28d..5330e6e 100644--- a/src/sim/walkers.ts+++ b/src/sim/walkers.ts@@ -142,7 +142,7 @@ export const SendWalkers = Game.System(const cursor = patrol.ok ? patrol.value.data.patrol.get().next : 0const tour = plan.tours[cursor % plan.tours.length]!if (patrol.ok) patrol.value.data.patrol.set({ next: (cursor + 1) % plan.tours.length })- else commands.insert(entity.id, Game.Command.entry(Patrol, { next: 1 % plan.tours.length }))+ else commands.insert(entity, Game.Command.entry(Patrol, { next: 1 % plan.tours.length }))const color = categoryColor[kinds[data.building.get().kind].category]const draft = Game.Command.spawn([Figure, { role: "walker", color }],@@ -262,7 +262,7 @@ export const Wander = Game.System(if (roam.service === "fire" && r.fire > 0) care.data.risk.set({ ...r, fire: 0 })if (row && roam.service === "health") {if (r.health > 0) care.data.risk.set({ ...r, health: 0 })- if (care.data.sick.present) commands.remove(care.entity.id, Sick)+ if (care.data.sick.present) commands.remove(care.entity, Sick)}if (row && roam.service === "order" && (r.order > 0 || r.thefts > 0)) care.data.risk.set({ ...r, order: 0, thefts: 0 })if (roam.service === "repair") {diff --git a/src/sim/work.ts b/src/sim/work.tsindex c2024af..9e0cd68 100644--- a/src/sim/work.ts+++ b/src/sim/work.ts@@ -206,29 +206,29 @@ export const Raise = Game.System(}if (total(works.owed) > 0 || works.done < needed) continueconst base = rules.kinds[data.building.get().kind], kind = asUpgraded(base, works.level)- commands.remove(entity.id, Works)- commands.insert(entity.id, Game.Command.entry(Upgraded, { level: works.level }))+ commands.remove(entity, Works)+ commands.insert(entity, Game.Command.entry(Upgraded, { level: works.level }))data.staff.set({ ...data.staff.get(), needed: kind.workers })const recipe = maybe(data.recipe), carriers = maybe(data.carriers), service = maybe(data.service)- if (recipe && kind.recipe) commands.insert(entity.id, Game.Command.entry(Recipe, { ...recipe, period: stepsOf(kind.recipe.seconds) }))+ if (recipe && kind.recipe) commands.insert(entity, Game.Command.entry(Recipe, { ...recipe, period: stepsOf(kind.recipe.seconds) }))if (shelves.ok && kind.holds) shelves.value.data.inventory.set({ ...shelves.value.data.inventory.get(), cap: kind.holds.cap })- if (carriers && kind.carriers) commands.insert(entity.id, Game.Command.entry(Carriers, { count: kind.carriers }))- if (service && kind.service) commands.insert(entity.id, Game.Command.entry(Service, { ...service, interval: stepsOf(kind.service.seconds), range: kind.service.range }))+ if (carriers && kind.carriers) commands.insert(entity, Game.Command.entry(Carriers, { count: kind.carriers }))+ if (service && kind.service) commands.insert(entity, Game.Command.entry(Service, { ...service, interval: stepsOf(kind.service.seconds), range: kind.service.range }))const was = (upgradeAt(base, works.level - 1)?.title ?? base.title).toLowerCase()write(resources.chronicle, elapsed(resources.time.get(), resources.charter.get()), `The ${was} is now ${anA(upgradeAt(base, works.level)!.title.toLowerCase())}.`, true)}for (const { entity, data } of queries.sites.each()) {if (total(data.site.get().owed) > 0) continue- commands.remove(entity.id, Site)- commands.insert(entity.id, Game.Command.entry(Rising, { ticks: Math.round(BUILD_TICKS * SITE_SHARE) }))+ commands.remove(entity, Site)+ commands.insert(entity, Game.Command.entry(Rising, { ticks: Math.round(BUILD_TICKS * SITE_SHARE) }))}for (const { entity, data } of queries.rising.each()) {const ticks = data.rising.get().ticks + 1if (ticks >= BUILD_TICKS) {- commands.remove(entity.id, Rising)+ commands.remove(entity, Rising)// Up and standing; its work (if it has any) says otherwise from here on.- if (data.status.present) commands.insert(entity.id, Game.Command.entry(Status, "idle"))+ if (data.status.present) commands.insert(entity, Game.Command.entry(Status, "idle"))} else data.rising.set({ ticks })}}