Implemented checks at least back to 2.0 functionality in new action engine

This commit is contained in:
Thaum Rystra
2024-04-17 19:37:38 +02:00
parent 24d7f3074a
commit a40163b9cf
21 changed files with 242 additions and 123 deletions

View File

@@ -30,7 +30,7 @@ type InputProvider = {
/**
* Get the details of a check or save
*/
//check(suggestedParams: CheckParams): Promise<CheckParams>;
check(suggestedParams: CheckParams): Promise<CheckParams>;
}
export type Advantage = 0 | 1 | -1;

View File

@@ -5,6 +5,7 @@ import getDeterministicDiceRoller from '/imports/api/engine/action/functions/use
// Dice rolls are done fresh, no cheating
export default function getReplayChoicesInputProvider(actionId: string, decisions: any[]):
InputProvider {
const decisionStack = [...decisions].reverse();
const dRoller = getDeterministicDiceRoller(actionId);
const replaySavedInput: InputProvider = {
nextStep() {
@@ -12,15 +13,18 @@ export default function getReplayChoicesInputProvider(actionId: string, decision
},
// To roll dice, ignore the user and use the deterministic dice roller again
rollDice(dice) {
decisions.pop();
decisionStack.pop();
return dRoller(dice);
},
choose() {
return Promise.resolve(decisions.pop());
return Promise.resolve(decisionStack.pop());
},
advantage() {
return Promise.resolve(decisions.pop());
}
return Promise.resolve(decisionStack.pop());
},
check() {
return Promise.resolve(decisionStack.pop());
},
}
return replaySavedInput;
}

View File

@@ -35,6 +35,9 @@ const inputProviderForTests: InputProvider = {
*/
async advantage(suggestedAdvantage) {
return suggestedAdvantage;
},
async check(suggestedParams) {
return suggestedParams;
}
}

View File

@@ -16,9 +16,9 @@ export default function saveInputChoices(action: EngineAction, userInput: InputP
for (const key in userInput) {
const oldFn = userInput[key];
// Make a new function that does the same thing, but saves the result to action._decisions
const newFn = (...args) => {
const result = oldFn(...args);
action._decisions.push(result);
const newFn = async (...args) => {
const result = await oldFn(...args);
action._decisions?.push(result);
return result;
}
newInputProvider[key] = newFn;