refactor: mass refactoring
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user