refactor: mass refactoring

This commit is contained in:
2026-04-01 13:36:16 +08:00
parent d0d051f547
commit 6740584fc8
11 changed files with 212 additions and 658 deletions
+10
View File
@@ -0,0 +1,10 @@
export type Command = {
name: string;
flags: Record<string, true>;
options: Record<string, string>;
params: string[];
}
// TODO implement this
export function parseCommand(input: string): Command {
}
+46
View File
@@ -0,0 +1,46 @@
import {Signal, signal} from "@preact/signals-core";
export type Entity = {
id: string;
};
export type EntityAccessor<T extends Entity> = {
id: string;
value: T;
}
export function createEntityCollection<T extends Entity>() {
const collection = signal({} as Record<string, Signal<T>>);
const remove = (...ids: string[]) => {
collection.value = Object.fromEntries(
Object.entries(collection.value).filter(([id]) => !ids.includes(id)),
);
};
const add = (...entities: T[]) => {
collection.value = {
...collection.value,
...Object.fromEntries(entities.map((entity) => [entity.id, signal(entity)])),
};
};
const get = (id: string) => {
return {
id,
get value(){
return collection.value[id]?.value;
},
set value(value: T){
const signal = collection.value[id];
if(signal)signal.value = value;
}
}
}
return {
collection,
remove,
add,
get
}
}
+12
View File
@@ -0,0 +1,12 @@
export interface RNG {
/** 设置随机数种子 */
(seed: number): void;
/** 获取一个[0,1)随机数 */
next(max?: number): number;
/** 获取一个[0,max)随机整数 */
nextInt(max: number): number;
}
// TODO: create a RNG implementation with the alea library