Implemented checks at least back to 2.0 functionality in new action engine
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ const inputProviderForTests: InputProvider = {
|
||||
*/
|
||||
async advantage(suggestedAdvantage) {
|
||||
return suggestedAdvantage;
|
||||
},
|
||||
async check(suggestedParams) {
|
||||
return suggestedParams;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user