multirepo

This commit is contained in:
azykov@mail.ru
2026-09-04 13:54:54 +03:00
parent 1553c48807
commit 5b2452aa50
41 changed files with 544 additions and 2 deletions
+47
View File
@@ -0,0 +1,47 @@
import { Behaviour, Converter, Storage } from "../behaviours";
import { SerializedBehaviour, SerializedConverter, SerializedStorage } from "../types";
export function deserializeBehaviour(value: SerializedBehaviour): Behaviour {
switch (value.kind) {
case 'converter':
return new Converter(value);
case 'storage':
return new Storage(value);
default:
throw new Error('Unknown behaviour');
}
}
export function serializeBehaviour(behaviour: Behaviour): SerializedBehaviour {
const base = {
id: behaviour.id,
kind: behaviour.kind,
inputLinks: { pins: behaviour.inputLinks },
};
switch (behaviour.kind) {
case 'converter': {
const converter = behaviour as Converter;
return {
...base,
cycleTime: converter.cycleTime,
storage: converter.getStorage(),
rules: {
cycleLength: converter.cycleLength,
inputRates: converter.inputRates,
outputRates: converter.outputRates,
}
} as (SerializedBehaviour & SerializedConverter);;
}
case 'storage':
const storage = behaviour as Storage;
return {
...base,
capacity: storage.capacity,
acceptsResources: storage.acceptsResources,
items: storage.getStorage(),
} as (SerializedBehaviour & SerializedStorage);
default:
throw new Error('Unknown behaviour');
}
}