Typescript all the parser things

This commit is contained in:
Thaum Rystra
2024-02-20 23:21:12 +02:00
parent 3ea492ee78
commit ac15512bc5
86 changed files with 926 additions and 718 deletions

View File

@@ -1,3 +1,5 @@
import Context from '../../../../parser/types/Context';
/**
* The result of running a task containing all the changes that need to be made to the listed
* targets
@@ -36,6 +38,22 @@ export default class TaskResult {
}
latestMutation.contents.push(content);
}
appendParserContextErrors(context: Context, targetIds) {
if (!context.errors?.length) return;
if (!this.mutations.length) {
this.mutations.push({ targetIds, contents: [] });
}
const latestMutation = this.mutations[this.mutations.length - 1]
if (!latestMutation.contents) {
latestMutation.contents = [];
}
context.errors?.forEach(error => {
latestMutation.contents?.push({
name: 'Error',
value: error.message,
});
});
}
}
export type Mutation = {

View File

@@ -8,7 +8,7 @@ import { getSingleProperty } from '/imports/api/engine/loadCreatures';
export default async function applyDamagePropTask(
task: DamagePropTask, action: EngineAction, result: TaskResult, userInput
): Promise<void> {
): Promise<number> {
const prop = task.prop;
if (task.targetIds.length > 1) {
@@ -74,7 +74,7 @@ export default async function applyDamagePropTask(
let damage, newValue, increment;
targetProp = await getSingleProperty(targetId, targetPropId);
if (!targetProp) return;
if (!targetProp) return value;
if (operation === 'set') {
const total = targetProp.total || 0;
@@ -128,4 +128,5 @@ export default async function applyDamagePropTask(
});
}
await applyTriggers(action, prop, [action.creatureId], 'damageProperty.after', userInput);
return increment;
}

View File

@@ -1,5 +1,5 @@
import { EngineAction } from '/imports/api/engine/action/EngineActions';
import Task from './Task';
import Task, { DamagePropTask, ItemAsAmmoTask, PropTask } from './Task';
import TaskResult from '/imports/api/engine/action/tasks/TaskResult';
import applyDamagePropTask from '/imports/api/engine/action/tasks/applyDamagePropTask';
import applyItemAsAmmoTask from '/imports/api/engine/action/tasks/applyItemAsAmmoTask';
@@ -7,9 +7,19 @@ import { getSingleProperty } from '/imports/api/engine/loadCreatures';
import applyProperties from '/imports/api/engine/action/applyProperties';
import InputProvider from '/imports/api/engine/action/functions/InputProvider';
// DamagePropTask promises a number of actual damage done
export default async function applyTask(
action: EngineAction, task: DamagePropTask, userInput: InputProvider
): Promise<number>
// Other tasks promise nothing
export default async function applyTask(
action: EngineAction, task: PropTask | ItemAsAmmoTask, userInput: InputProvider
): Promise<void>
export default async function applyTask(
action: EngineAction, task: Task, userInput: InputProvider
): Promise<void> {
): Promise<void | number> {
action.taskCount += 1;
if (action.taskCount > 100) throw 'Only 100 properties can be applied at once';