UNPKG

prendy

Version:

Make games with prerendered backdrops using babylonjs and repond

47 lines (46 loc) 1.88 kB
import { makeEffects, startNewItemEffect, stopNewEffect } from "repond"; import { getUsefulStoryStuff } from "./prendyRuleMakers"; export function makePlaceLoadEffects(atStartOfEachPlace, callbacksMap) { return makeEffects(({ itemEffect }) => ({ whenPlaceFinishedLoading: itemEffect({ run() { // onNextTick(() => { const usefulStoryStuff = getUsefulStoryStuff(); const { nowPlaceName } = usefulStoryStuff; atStartOfEachPlace?.(usefulStoryStuff); callbacksMap[nowPlaceName]?.(usefulStoryStuff); // }); }, check: { type: "global", prop: ["isLoadingBetweenPlaces"], becomes: false }, // step: "respondToNewPlace", step: "respondToNewPlaceStory", atStepEnd: true, }), })); } export function makePlaceUnloadEffects(callbacksMap) { return makeEffects(({ itemEffect }) => ({ whenPlaceFinishedUnloading: itemEffect({ run({ prevValue: prevPlace, newValue: newPlace }) { let effectId = startNewItemEffect({ run() { stopNewEffect(effectId); // console.log("unload rules for", prevPlace); const usefulStoryStuff = getUsefulStoryStuff(); callbacksMap[prevPlace]?.(usefulStoryStuff); }, check: { type: "global", prop: ["isLoadingBetweenPlaces"], becomes: false, }, atStepEnd: true, step: "input", }); }, check: { type: "global", prop: ["nowPlaceName"] }, step: "story", atStepEnd: true, }), })); }