break_eternity
This commit is contained in:
+9
-8
@@ -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[];
|
||||
}
|
||||
Reference in New Issue
Block a user