break_eternity

This commit is contained in:
azykov@mail.ru
2026-08-31 22:21:53 +03:00
parent 90501176ef
commit b9c0c0ee28
6 changed files with 34 additions and 22 deletions
+9 -8
View File
@@ -1,9 +1,10 @@
import Decimal, { DecimalSource } from "break_eternity.js";
import { Behaviour } from "../engine/functions";
import { deserializeBehaviour } from "../engine/saveLoad";
export type Resource = 'wood' | 'plank' | 'stone';
export type Resources = Record<Resource, number>;
export type Resources = Record<Resource, Decimal>;
export type Node = {
id: string;
@@ -12,11 +13,11 @@ export type Node = {
}
export class Game {
public time: number;
public time: Decimal;
public readonly nodes: Node[];
constructor(source: SerializedGame) {
this.time = source.time;
this.time = new Decimal(source.time);
this.nodes = source.nodes.map((node) => ({
id: node.id,
name: node.name,
@@ -25,7 +26,7 @@ export class Game {
}
public tick(deltaTime: number) {
this.time += deltaTime;
this.time = this.time.add(deltaTime);
const behavioursById = new Map(this.nodes.map((node) => [node.behaviour.id, node.behaviour]));
@@ -36,7 +37,7 @@ export class Game {
}
public reset() {
this.time = 0;
this.time = Decimal.dZero;
for (const node of this.nodes)
node.behaviour.reset();
}
@@ -49,7 +50,7 @@ export class Game {
export type SerializedConverterInput = {
resource: Resource;
rate: number;
rate: DecimalSource;
link: {
target: SerializedNodeBehaviour['id'],
resource: Resource,
@@ -58,7 +59,7 @@ export type SerializedConverterInput = {
export type SerializedConverterOutput = {
resource: Resource;
rate: number;
rate: DecimalSource;
}
export type SerializedConverterInputs = {
@@ -90,6 +91,6 @@ export type SerializedNode = {
}
export type SerializedGame = {
time: number;
time: DecimalSource;
nodes: SerializedNode[];
}