feat: check function
This commit is contained in:
parent
a226a9516c
commit
82876d47c0
|
|
@ -38,7 +38,21 @@ export function createYarnStore(element: HTMLElement, props: RunnerOptions){
|
|||
const ast = parseYarn(content);
|
||||
const program = compile(ast);
|
||||
|
||||
return new YarnRunner(program, props);
|
||||
const runner = new YarnRunner(program, {
|
||||
functions: {
|
||||
check(id: string, stat: string): number {
|
||||
const statVal = runner.getVariable(stat) as number || 10;
|
||||
const pass = Math.ceil(Math.random() * 20) <= statVal;
|
||||
const key = `${id}_${pass ? 'pass' : 'fail'}`;
|
||||
const progress = runner.getVariable(key) as number || 0;
|
||||
const newProgress = progress + Math.ceil(Math.random() * 4);
|
||||
runner.setVariable(key, newProgress);
|
||||
return pass ? newProgress : -newProgress;
|
||||
}
|
||||
},
|
||||
startAt: props.startAt,
|
||||
});
|
||||
return runner;
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize YarnRunner:', error);
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue