prendy
Version:
Make games with prerendered backdrops using babylonjs and repond
101 lines (100 loc) • 3.87 kB
JavaScript
import { addSubEvents, makeEventTypes, II } from "repond-events";
import { get2DAngleBetweenCharacters, getCharDollStuff, } from "../helpers/prendyUtils/characters";
import { Vector3 } from "@babylonjs/core";
import { getState } from "repond";
// type whor =
export const characterEvents = makeEventTypes(({ event }) => ({
setAnimation: event({
run: ({ who, to }, { liveId, isFirstAdd }) => {
if (!isFirstAdd)
return;
const { dollName } = getCharDollStuff(who);
addSubEvents(liveId, [II("doll", "setAnimation", { which: dollName, to })]);
},
params: {
who: "",
to: "", // AnimationNameFromModel might keep the type better
},
}),
setPosition: event({
run: ({ who, to }, { isFirstAdd, liveId }) => {
if (!isFirstAdd)
return;
const { dollName } = getCharDollStuff(who);
addSubEvents(liveId, [II("doll", "setPosition", { which: dollName, to })]);
},
params: { who: "", to: new Vector3(0, 0, 0) },
}),
setRotationY: event({
run: ({ who, to: to }, { isFirstAdd, liveId }) => {
if (!isFirstAdd)
return;
const { dollName } = getCharDollStuff(who);
addSubEvents(liveId, [II("doll", "setRotationY", { which: dollName, to })]);
},
params: { who: "", to: 0 },
}),
springRotation: event({
run: ({ who, to }, { isFirstAdd, liveId }) => {
if (!isFirstAdd)
return;
const { dollName } = getCharDollStuff(who);
addSubEvents(liveId, [II("doll", "springRotationY", { which: dollName, to })]);
},
params: { who: "", to: 0 },
}),
springAddToRotationY: event({
run: ({ who, addedRotation }, { isFirstAdd, liveId }) => {
if (!isFirstAdd)
return;
const { dollName } = getCharDollStuff(who);
addSubEvents(liveId, [II("doll", "springAddToRotationY", { which: dollName, addedRotation })]);
},
params: { who: "", addedRotation: 0 },
}),
lookAtOther: event({
run: ({ whoA: whoA, whoB }, { isFirstAdd, liveId }) => {
if (!isFirstAdd)
return;
const { dollName } = getCharDollStuff(whoB);
const angle = get2DAngleBetweenCharacters(whoB, whoA);
addSubEvents(liveId, [II("doll", "springRotationY", { which: dollName, angle })]);
},
params: { whoA: "", whoB: "" },
}),
lookAtEachother: event({
run: ({ whoA, whoB }, { isFirstAdd, liveId }) => {
if (!isFirstAdd)
return;
addSubEvents(liveId, [
II("character", "lookAtOther", { whoA, whoB }),
II("character", "lookAtOther", { whoA: whoB, whoB: whoA }),
]);
},
params: { whoA: "", whoB: "" },
}),
lookAtSpot: event({
run: async ({ place, spot, who }, { isFirstAdd, liveId }) => {
if (!isFirstAdd)
return;
const { playerCharacter } = getState().global.main;
const character = who ?? playerCharacter;
const { dollName } = getCharDollStuff(character);
addSubEvents(liveId, [II("doll", "lookAtSpot", { which: dollName, place, spot })]);
},
params: {
place: "",
spot: "",
who: undefined,
},
}),
moveAt2DAngle: event({
run: ({ who, angle }, { isFirstAdd, liveId }) => {
if (!isFirstAdd)
return;
const { dollName } = getCharDollStuff(who);
addSubEvents(liveId, [II("doll", "moveAt2DAngle", { which: dollName, angle })]);
},
params: { who: "", angle: 0 },
}),
}));