UNPKG

react-simple-game-engine

Version:

[WIP] not able to use in currently. <!-- Document cumming soon... -->

65 lines (64 loc) 2.55 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; import { useCallback, useContext, useEffect, useState } from "react"; import { SoundStoreKey } from "../export-enums"; import { UISceneContext } from "../react-context"; import { Saver } from "./saver"; export function SoundOnceWatcher(_a) { var children = _a.children; var scene = useContext(UISceneContext); var _b = useState(scene.soundOnceOptions), values = _b[0], setValues = _b[1]; useEffect(function () { return scene.onSoundOnceOptionsChange(function (options) { setValues(function (prev) { return (__assign(__assign({}, prev), options)); }); }); }, [scene]); var toggle = useCallback(function () { var next = !scene.soundOnceOptions.canPlay; scene.soundOnceOptions = { canPlay: next, }; Saver.set(SoundStoreKey.ONCE, next); }, []); var set = useCallback(function (on) { scene.soundOnceOptions = { canPlay: on, }; Saver.set(SoundStoreKey.ONCE, on); }, []); return _jsx(_Fragment, { children: children(__assign(__assign({}, values), { toggle: toggle, set: set })) }); } export function SoundBackgroundWatcher(_a) { var children = _a.children; var scene = useContext(UISceneContext); var _b = useState(scene.soundBackgroundOptions), values = _b[0], setValues = _b[1]; useEffect(function () { return scene.onSoundBackgroundOptionsChange(function (options) { setValues(function (prev) { return (__assign(__assign({}, prev), options)); }); }); }, [scene]); var toggle = useCallback(function () { var next = !scene.soundBackgroundOptions.canPlay; scene.soundBackgroundOptions = { canPlay: next, }; Saver.set(SoundStoreKey.BACKGROUND, next); }, []); var set = useCallback(function (on) { scene.soundBackgroundOptions = { canPlay: on, }; Saver.set(SoundStoreKey.BACKGROUND, on); }, []); return _jsx(_Fragment, { children: children(__assign(__assign({}, values), { toggle: toggle, set: set })) }); }