break_eternity and eternal_notations. cmd line option for time
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import Decimal from "break_eternity.js";
|
||||
import { ResourceNames, type PartialResources, type Resource } from "../types";
|
||||
|
||||
export class ResourceSet {
|
||||
private items = new Map<Resource, number>();
|
||||
private items = new Map<Resource, Decimal>();
|
||||
|
||||
public static from(source: PartialResources): ResourceSet {
|
||||
const inst = new ResourceSet();
|
||||
inst.items = new Map<Resource, number>(Object.entries(source) as [Resource, number][]);
|
||||
inst.items = new Map<Resource, Decimal>(Object.entries(source) as [Resource, Decimal][]);
|
||||
return inst;
|
||||
}
|
||||
|
||||
@@ -13,11 +14,11 @@ export class ResourceSet {
|
||||
return ResourceSet.from(this.toObject());
|
||||
}
|
||||
|
||||
public get(key: Resource): number {
|
||||
return this.items.get(key) ?? 0;
|
||||
public get(key: Resource): Decimal {
|
||||
return this.items.get(key) ?? Decimal.dZero;
|
||||
}
|
||||
|
||||
public set(key: Resource, value: number): void {
|
||||
public set(key: Resource, value: Decimal): void {
|
||||
this.items.set(key, value);
|
||||
}
|
||||
|
||||
@@ -26,31 +27,31 @@ export class ResourceSet {
|
||||
}
|
||||
|
||||
public gte(arg: ResourceSet): boolean {
|
||||
return this.predicate((res) => this.get(res) >= arg.get(res));
|
||||
return this.predicate((res) => this.get(res).gte(arg.get(res)));
|
||||
}
|
||||
|
||||
public static transform(target: ResourceSet, predicate: (res: Resource) => number): void {
|
||||
public static transform(target: ResourceSet, predicate: (res: Resource) => Decimal): void {
|
||||
for (const res of ResourceNames)
|
||||
target.set(res, predicate(res));
|
||||
}
|
||||
|
||||
public sum(arg: ResourceSet): ResourceSet {
|
||||
const inst = new ResourceSet();
|
||||
ResourceSet.transform(inst, (res) => this.get(res) + arg.get(res));
|
||||
ResourceSet.transform(inst, (res) => this.get(res).plus(arg.get(res)));
|
||||
return inst;
|
||||
}
|
||||
|
||||
public add(arg: ResourceSet): void {
|
||||
ResourceSet.transform(this, (res) => this.get(res) + arg.get(res));
|
||||
ResourceSet.transform(this, (res) => this.get(res).plus(arg.get(res)));
|
||||
}
|
||||
|
||||
public remove(arg: ResourceSet): void {
|
||||
ResourceSet.transform(this, (res) => this.get(res) - arg.get(res));
|
||||
ResourceSet.transform(this, (res) => this.get(res).minus(arg.get(res)));
|
||||
}
|
||||
|
||||
public times(factor: number): ResourceSet {
|
||||
const inst = new ResourceSet();
|
||||
ResourceSet.transform(inst, (res) => this.get(res) * factor);
|
||||
ResourceSet.transform(inst, (res) => this.get(res).multiply(factor));
|
||||
return inst;
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -1,6 +1,7 @@
|
||||
import Decimal from 'break_eternity.js';
|
||||
import { Game } from './game';
|
||||
import type { ResourceGeneratorRule } from './rules';
|
||||
import type { PartialResources, Resource } from './types';
|
||||
import type { PartialResources, Resource, Resources } from './types';
|
||||
|
||||
export * from './types';
|
||||
export * from './rules';
|
||||
@@ -33,9 +34,9 @@ function simpleResGen(params: SimpleResGenParams): ResourceGeneratorRule {
|
||||
Object.entries(p)
|
||||
.map(([res, rp]) => [
|
||||
res,
|
||||
(rp.offset ?? 0) + Math.pow(lvl, rp.power ?? 1) * (rp.factor ?? 0),
|
||||
new Decimal((rp.offset ?? 0) + Math.pow(lvl, rp.power ?? 1) * (rp.factor ?? 0)),
|
||||
])
|
||||
);
|
||||
) as Resources;
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -60,7 +61,7 @@ export function makeGame(): Game {
|
||||
generation: { RED: { offset: 3, power: 1.5, factor: 1 } },
|
||||
openPrice: { RED: { offset: 10, power: 2.1, factor: 10 } }
|
||||
}),
|
||||
...['orange', 'yellow', 'green', 'cyan', 'blue', 'violet', ...Array(20)]
|
||||
...['orange', 'yellow', 'green', 'cyan', 'blue', 'violet']
|
||||
.map((color, idx) => simpleResGen({
|
||||
name: color,
|
||||
period: idx + 2,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import Decimal from "break_eternity.js";
|
||||
|
||||
export const ResourceNames = ['RED'] as const;
|
||||
export type Resource = (typeof ResourceNames)[number];
|
||||
|
||||
export type Resources = Record<Resource, number>;
|
||||
export type PartialResources = Partial<Record<Resource, number>>;
|
||||
export type Resources = Record<Resource, Decimal>;
|
||||
export type PartialResources = Partial<Resources>;
|
||||
|
||||
Reference in New Issue
Block a user