mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-30 02:24:42 +08:00
update: state, event, condition, data.event.types
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
export type RNG = (max?: number, min?: number) => number
|
||||
export function random(max: number, min: number = 0, rng?: RNG): number {
|
||||
if (rng) return rng(max, min)
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min
|
||||
}
|
||||
export function pick<T>(items: T[], rng?: RNG) {
|
||||
if (items.length === 0) return null
|
||||
return items[random(items.length - 1, 0, rng)]
|
||||
}
|
||||
export type WeightItem<T> = [T, number]
|
||||
export function pickWeight<T>(items: WeightItem<T>[], rng?: RNG) {
|
||||
if (items.length === 0) return null
|
||||
const totalWeight = items.reduce((sum, [, weight]) => sum + weight, 0)
|
||||
let mark = random(totalWeight - 1, 0, rng)
|
||||
for (const [item, weight] of items) {
|
||||
if (mark < weight) return item
|
||||
mark -= weight
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function sum(arr: number[]) {
|
||||
return arr.reduce((sum, v) => sum + v, 0)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@remake/vitex",
|
||||
"type": "module",
|
||||
"version": "3.0.0",
|
||||
"main": "./index.ts",
|
||||
"author": "Vick Scarlet <vick@syaro.io>",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"test": "bun test"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "../../package.json"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Environment setup & latest features
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"module": "Preserve",
|
||||
"moduleDetection": "force",
|
||||
"types": ["bun"],
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noImplicitOverride": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noPropertyAccessFromIndexSignature": false,
|
||||
"noImplicitAny": true
|
||||
},
|
||||
"include": ["**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user