feat: Implement primitive WorldClock

This commit is contained in:
2026-07-06 08:02:06 +05:30
parent d4a2de8f57
commit 496b17faf0
4 changed files with 30 additions and 1 deletions

View File

@@ -37,5 +37,10 @@
"typescript": "^6.0.3",
"typescript-eslint": "^8.62.1",
"zod": "^4.4.3"
},
"dependencies": {
"@langchain/google-genai": "^2.2.0",
"@types/node": "^20.19.43",
"dotenv": "^17.4.2"
}
}

View File

@@ -7,6 +7,8 @@
".": "./dist/index.js"
},
"dependencies": {
"@langchain/google-genai": "^2.2.0",
"@types/node": "^26.1.0",
"better-sqlite3": "^12.11.1"
}
}

View File

@@ -0,0 +1,19 @@
export class WorldClock {
private currentTime: Date;
constructor(startTime: Date = new Date(1999, 4, 14, 18, 0)) {
this.currentTime = startTime;
}
advance(minutes: number): void {
this.currentTime = new Date(this.currentTime.getTime() + minutes * 60_000);
}
get(): Date {
return this.currentTime;
}
static fromISOString(iso: string): WorldClock {
return new WorldClock(new Date(iso));
}
}

View File

@@ -1,5 +1,6 @@
import { AttributableObject } from "./attribute.js";
import { Entity } from "./entity.js";
import { WorldClock } from "./clock.js";
export class WorldState extends AttributableObject {
/**
@@ -7,9 +8,11 @@ export class WorldState extends AttributableObject {
* Universe's current state (distinct from how it started)
*/
readonly entities: Map<string, Entity> = new Map();
readonly clock: WorldClock;
constructor(id?: string) {
constructor(id?: string, startTime?: Date) {
super(id);
this.clock = new WorldClock(startTime);
}
addEntity(entity: Entity): void {