prendy
Version:
Make games with prerendered backdrops using babylonjs and repond
64 lines (63 loc) • 2.29 kB
JavaScript
import { defaultPosition } from "chootils/dist/points2d";
import { forEach } from "chootils/dist/loops";
export default function miniBubbles(prendyAssets) {
const { characterNames, characterOptions } = prendyAssets;
const getDefaultState = (_itemId, options // TODO maybe this should be a partial of the initial statea, but might need to add types twice..
) => ({
isVisible: false,
isFullyHidden: true,
text: "❕",
forCharacter: options?.character ?? "walker",
position: defaultPosition(),
});
const getDefaultRefs = () => ({
bubbleRef: null,
textRef: null,
videoRef: null, // note: only the source changes, the video element is the same?
});
function makeAutmaticCharacterMinibubbleStartStates() {
const partialStates = {};
forEach(characterNames, (characterName) => {
partialStates[characterName] = getDefaultState(characterName, {
character: characterName,
});
});
return partialStates;
}
// const startStates: InitialItemsState<typeof state> = {
const startStates = {
...makeAutmaticCharacterMinibubbleStartStates(),
// walkerMiniBubble: state("walkerMiniBubble"), // NOTE This only works for "walker" at the moment
// foxBubble: { ...state("foxBubble"), forCharacter: "fox" as CharacterName },
// flyBubble: { ...state("flyBubble"), forCharacter: "fly" as CharacterName },
// eggBubble: {
// ...state("eggBubble"),
// forCharacter: "startegg" as CharacterName,
// },
};
return { getDefaultState, getDefaultRefs, startStates };
}
// export type Store_MiniBubbles<T_ItemName extends string, CharacterName> = {
// state: () => {
// isVisible: boolean;
// isFullyHidden: boolean;
// text: string;
// forCharacter: CharacterName;
// position: Point2D;
// };
// refs: () => {
// bubbleRef: null | any;
// textRef: null | any;
// videoRef: null | HTMLVideoElement;
// };
// startStates: Record<
// T_ItemName,
// {
// isVisible: boolean;
// isFullyHidden: boolean;
// text: string;
// forCharacter: CharacterName;
// position: Point2D;
// }
// >;
// };