initial commit
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { Behaviour } from "../engine/functions";
|
||||
import { deserializeBehaviour } from "../engine/saveLoad";
|
||||
|
||||
export type Resource = 'wood' | 'plank';
|
||||
|
||||
export type Resources = Record<Resource, number>;
|
||||
|
||||
export type Node = {
|
||||
id: string;
|
||||
name: string;
|
||||
behaviour: Behaviour;
|
||||
}
|
||||
|
||||
export class Game {
|
||||
public time: number;
|
||||
public readonly nodes: Node[];
|
||||
|
||||
constructor(source: SerializedGame) {
|
||||
this.time = source.time;
|
||||
this.nodes = source.nodes.map((node) => ({
|
||||
id: node.id,
|
||||
name: node.name,
|
||||
behaviour: deserializeBehaviour(node.behaviour),
|
||||
}));
|
||||
}
|
||||
|
||||
public tick(deltaTime: number) {
|
||||
this.time += deltaTime;
|
||||
for (const node of this.nodes)
|
||||
node.behaviour.tick(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
export type SerializedConverterInput = {
|
||||
resource: Resource;
|
||||
rate: number;
|
||||
link: {
|
||||
target: SerializedNodeBehaviour['id'],
|
||||
resource: Resource,
|
||||
}
|
||||
}
|
||||
|
||||
export type SerializedConverterOutput = {
|
||||
resource: Resource;
|
||||
rate: number;
|
||||
}
|
||||
|
||||
export type SerializedConverterInputs = {
|
||||
pins: SerializedConverterInput[];
|
||||
}
|
||||
|
||||
export type SerializedConverterOutputs = {
|
||||
pins: SerializedConverterOutput[];
|
||||
}
|
||||
|
||||
export type SerializedConverter = {
|
||||
kind: 'converter';
|
||||
}
|
||||
|
||||
export type SerializedStorage = {
|
||||
kind: 'storage',
|
||||
}
|
||||
|
||||
export type SerializedNodeBehaviour = {
|
||||
id: string;
|
||||
inputs: SerializedConverterInputs;
|
||||
outputs: SerializedConverterOutputs;
|
||||
} & (SerializedConverter | SerializedStorage);
|
||||
|
||||
export type SerializedNode = {
|
||||
id: Node['id'],
|
||||
name: Node['name'],
|
||||
behaviour: SerializedNodeBehaviour,
|
||||
}
|
||||
|
||||
export type SerializedGame = {
|
||||
time: number;
|
||||
nodes: SerializedNode[];
|
||||
}
|
||||
Reference in New Issue
Block a user