too
This commit is contained in:
parent
4fdc567e08
commit
e00bfd8879
51 changed files with 1203 additions and 833 deletions
|
|
@ -12,11 +12,6 @@
|
|||
return Number.isFinite(n) ? n : fallback;
|
||||
}
|
||||
|
||||
function toList(value) {
|
||||
if (Array.isArray(value)) return value.filter(Boolean).map(String);
|
||||
if (value == null || value === "") return [];
|
||||
return [String(value)];
|
||||
}
|
||||
|
||||
function hasOwnFn(obj, key) {
|
||||
return typeof obj?.[key] === "function";
|
||||
|
|
@ -51,9 +46,7 @@
|
|||
phrase: String(input.phrase || input.label || id),
|
||||
weight: finiteOr(input.weight, 1),
|
||||
priority: finiteOr(input.priority, 0),
|
||||
tags: toList(input.tags),
|
||||
timerBacked: Boolean(input.timerBacked),
|
||||
interruptible: input.interruptible !== false,
|
||||
};
|
||||
|
||||
const originalCanStart = hasOwnFn(input, "canStart") ? input.canStart : null;
|
||||
|
|
@ -98,11 +91,6 @@
|
|||
return spec.label;
|
||||
};
|
||||
|
||||
Object.defineProperty(spec, "__actionSpec", {
|
||||
value: true,
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
});
|
||||
return spec;
|
||||
}
|
||||
|
||||
|
|
@ -135,14 +123,14 @@
|
|||
const canCtx = isObject(ctx) ? ctx : {};
|
||||
if (hasOwnFn(spec, "canStart") && !spec.canStart(tarinai, world, canCtx)) return false;
|
||||
const nextCtx = buildActionContext(tarinai, world, canCtx, spec);
|
||||
return hasOwnFn(spec, "start") ? spec.start(tarinai, world, nextCtx) : spec.run?.(tarinai, world, nextCtx);
|
||||
return spec.start(tarinai, world, nextCtx);
|
||||
}
|
||||
|
||||
function tickTarinaiAction(action, tarinai, world, dt = 0, needs = null, ctx = {}) {
|
||||
const spec = resolveActionSpec(action);
|
||||
if (!spec) return undefined;
|
||||
const nextCtx = buildActionContext(tarinai, world, ctx, spec);
|
||||
return hasOwnFn(spec, "tick") ? spec.tick(tarinai, world, dt, needs, nextCtx) : spec.update?.(tarinai, world, dt, needs, nextCtx);
|
||||
return spec.tick(tarinai, world, dt, needs, nextCtx);
|
||||
}
|
||||
|
||||
function finishTarinaiAction(action, tarinai, world, ctx = {}) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue