prendy
Version:
Make games with prerendered backdrops using babylonjs and repond
73 lines (72 loc) • 3.28 kB
JavaScript
import { forEach } from "chootils/dist/loops";
import { defaultPosition as defaultPosition2d } from "chootils/dist/points2d";
import { mover3dRefs, mover3dState, moverRefs, moverState } from "repond-movers";
import get_dollStoreUtils from "./dollStoreUtils";
const HIDDEN_POSITION = { x: 0, y: 0, z: -1000 };
export default function dolls(prendyAssets) {
const { modelNames, dollNames, modelInfoByName, dollOptions } = prendyAssets;
const { defaultInRange, makeModelAnimWeightsMoverState, makeToggledMeshesState, modelMoverRefs, modelOtherMeshesRefs, } = get_dollStoreUtils(prendyAssets);
const defaultModelName = modelNames[0];
const getDefaultState = (_dollName, modelName) => {
const safeModelName = modelName ?? defaultModelName;
const { animationNames } = modelInfoByName[safeModelName];
return {
modelName: safeModelName, // to reference in refs aswell
// New room
goalSpotNameAtNewPlace: null, // when going to new place, start at this spot
goalPositionAtNewPlace: null, // when going to new place, start at this spot
// Movers
...mover3dState("position", {
value: HIDDEN_POSITION,
valueGoal: HIDDEN_POSITION,
}), // could have semnticolor icons split by numbers too
...moverState("rotationY"),
//
nowWalkSpeed: 0,
positionOnScreen: defaultPosition2d(),
// nowAnimation: animationNames[0] as AnimationNameByModel[T_ModelName],
// animation Weights mover
...makeModelAnimWeightsMoverState(safeModelName)("animWeights"),
toggledMeshes: makeToggledMeshesState(safeModelName),
nowAnimation: animationNames[0], // NOTE AnimationNameFromDoll might work here?
animationLoops: true, // currently unused
//
inRange: defaultInRange(),
//
isVisible: true,
};
};
const getDefaultRefs = (dollName, itemState) => {
const modelName = itemState.modelName;
return {
// local refs ( maybe replace with just the container hm)
meshRef: null,
otherMeshes: modelOtherMeshesRefs(modelName),
entriesRef: null,
aniGroupsRef: null,
assetRefs: null,
groundRef: null,
canGoThroughWalls: false,
...mover3dRefs("position", {
mass: 20,
damping: 0.5,
friction: 0.5,
stiffness: 0.65,
}), // maybe also start movers using the main name
...moverRefs("rotationY", { mass: 100, damping: 2, stiffness: 20, friction: 20 }),
...modelMoverRefs(modelName, "animWeights"),
};
};
function makeAutmaticModelDollStartStates() {
const partialDollStates = {};
forEach(dollNames, (dollName) => {
partialDollStates[dollName] = getDefaultState(dollName, dollOptions[dollName].model);
});
return partialDollStates;
}
const startStates = {
// Automatically make dolls
...makeAutmaticModelDollStartStates(),
};
return { startStates, getDefaultState, getDefaultRefs };
}