minor converter rates refactoring
This commit is contained in:
+13
-5
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user