refactor: yarn runner man
This commit is contained in:
@@ -4,6 +4,7 @@ import {compile, parseYarn, YarnRunner} from "../../yarn-spinner";
|
||||
import {loadElementSrc, resolvePath} from "../utils/path";
|
||||
import {createStore} from "solid-js/store";
|
||||
import {RunnerOptions} from "../../yarn-spinner/runtime/runner";
|
||||
import {getTtrpgFunctions} from "./ttrpgRunner";
|
||||
|
||||
type YarnSpinnerStore = {
|
||||
dialogueHistory: (RuntimeResult | OptionsResult['options'][0])[],
|
||||
@@ -12,7 +13,7 @@ type YarnSpinnerStore = {
|
||||
runnerInstance: YarnRunner | null,
|
||||
}
|
||||
|
||||
export function createYarnStore(element: HTMLElement, props: RunnerOptions){
|
||||
export function createYarnStore(element: HTMLElement, props: {start: string}){
|
||||
const [store, setStore] = createStore<YarnSpinnerStore>({
|
||||
dialogueHistory: [],
|
||||
currentOptions: null,
|
||||
@@ -39,19 +40,11 @@ export function createYarnStore(element: HTMLElement, props: RunnerOptions){
|
||||
const program = compile(ast);
|
||||
|
||||
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,
|
||||
startAt: props.start,
|
||||
});
|
||||
const {commands, functions} = getTtrpgFunctions(runner);
|
||||
runner.registerFunctions(functions);
|
||||
runner.registerCommands(commands);
|
||||
return runner;
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize YarnRunner:', error);
|
||||
|
||||
Reference in New Issue
Block a user