minor converter rates refactoring

This commit is contained in:
azykov@mail.ru
2026-08-31 22:10:16 +03:00
parent d96a6e2e92
commit 90501176ef
2 changed files with 44 additions and 24 deletions
+13 -5
View File
@@ -1,20 +1,28 @@
import { defaultGame } from "../prefabs/game";
import { Game, SerializedGame, SerializedNodeBehaviour } from "../types";
import { Behaviour, behaviours } from "./functions";
import { Behaviour, behaviours, Converter } from "./functions";
export function serializeBehaviour(behaviour: Behaviour): SerializedNodeBehaviour {
switch (behaviour.kind) {
case 'converter':
case 'converter': {
const converter = behaviour as Converter;
return {
id: behaviour.id,
id: converter.id,
kind: 'converter',
inputs: {
pins: behaviour.inputs.pins.map((pin) => ({ ...pin })),
pins: converter.inputs.pins.map((pin) => ({
...pin,
rate: converter.inputRates[pin.resource] ?? 0,
})),
},
outputs: {
pins: behaviour.outputs.pins.map((pin) => ({ ...pin })),
pins: converter.outputs.pins.map((pin) => ({
...pin,
rate: converter.outputRates[pin.resource] ?? 0,
})),
},
};
}
default:
throw new Error('Unknown behaviour');
}