converter now has cycleLength. storage save load fix

This commit is contained in:
azykov@mail.ru
2026-09-01 09:52:52 +03:00
parent b9c0c0ee28
commit b14b60858c
5 changed files with 148 additions and 81 deletions
+18 -13
View File
@@ -31,14 +31,14 @@ export class Game {
const behavioursById = new Map(this.nodes.map((node) => [node.behaviour.id, node.behaviour]));
for (const node of this.nodes)
node.behaviour.produce(deltaTime);
node.behaviour.tick(deltaTime);
for (const node of this.nodes)
node.behaviour.pull(deltaTime, (id) => behavioursById.get(id));
node.behaviour.pull((id) => behavioursById.get(id));
}
public reset() {
this.time = Decimal.dZero;
for (const node of this.nodes)
for (const node of this.nodes)
node.behaviour.reset();
}
@@ -48,30 +48,35 @@ export class Game {
}
}
export type SerializedConverterInput = {
export type SerializedInput = {
resource: Resource;
rate: DecimalSource;
link: {
target: SerializedNodeBehaviour['id'],
resource: Resource,
}
}
export type SerializedConverterOutput = {
export type SerializedOutput = {
resource: Resource;
rate: DecimalSource;
}
export type SerializedConverterInputs = {
pins: SerializedConverterInput[];
export type SerializedInputs = {
pins: SerializedInput[];
}
export type SerializedConverterOutputs = {
pins: SerializedConverterOutput[];
export type SerializedOutputs = {
pins: SerializedOutput[];
}
export type SerializedConverter = {
kind: 'converter';
cycleTime?: DecimalSource;
storage?: Partial<Record<Resource, DecimalSource>>;
rules: {
cycleLength: DecimalSource;
inputRates?: Partial<Record<Resource, DecimalSource>>;
outputRates?: Partial<Record<Resource, DecimalSource>>;
}
}
export type SerializedStorage = {
@@ -80,8 +85,8 @@ export type SerializedStorage = {
export type SerializedNodeBehaviour = {
id: string;
inputs: SerializedConverterInputs;
outputs: SerializedConverterOutputs;
inputs: SerializedInputs;
outputs: SerializedOutputs;
} & (SerializedConverter | SerializedStorage);
export type SerializedNode = {