authorize user now resets state, polytan progress merged with game progress

This commit is contained in:
ad044 2021-03-28 02:56:55 +04:00
parent 0bdefcb8fe
commit 59b882e68f
7 changed files with 87 additions and 51 deletions

View file

@ -10,25 +10,37 @@ describe("Idle helpers", () => {
const fullyUnlocked = {
body: true,
head: true,
leftArm: true,
rightArm: true,
leftLeg: true,
rightLeg: true,
left_arm: true,
right_arm: true,
left_leg: true,
right_leg: true,
};
useStore.setState({ polytanUnlockedParts: fullyUnlocked });
const state = useStore.getState();
useStore.setState({
gameProgress: {
...state.gameProgress,
polytan_unlocked_parts: fullyUnlocked,
},
});
expect(isPolytanFullyUnlocked()).toEqual(true);
const partiallyUnlocked = {
body: false,
head: true,
leftArm: false,
rightArm: true,
leftLeg: true,
rightLeg: true,
left_arm: false,
right_arm: true,
left_leg: true,
right_leg: true,
};
useStore.setState({ polytanUnlockedParts: partiallyUnlocked });
useStore.setState({
gameProgress: {
...state.gameProgress,
polytan_unlocked_parts: partiallyUnlocked,
},
});
expect(isPolytanFullyUnlocked()).toEqual(false);
});

View file

@ -19,7 +19,9 @@ const PolytanBear = memo(() => {
const rightArmTex = useLoader(THREE.TextureLoader, rightArm);
const rightLegTex = useLoader(THREE.TextureLoader, rightLeg);
const unlockedParts = useStore((state) => state.polytanUnlockedParts);
const unlockedParts = useStore(
(state) => state.gameProgress.polytan_unlocked_parts
);
return (
<>
@ -46,28 +48,28 @@ const PolytanBear = memo(() => {
<spriteMaterial
attach="material"
map={leftLegTex}
visible={unlockedParts.leftLeg}
visible={unlockedParts.left_leg}
/>
</sprite>
<sprite scale={[1.5, 1.9, 0]} position={[1.2, -0.4, 0]}>
<spriteMaterial
attach="material"
map={leftArmTex}
visible={unlockedParts.leftArm}
visible={unlockedParts.left_arm}
/>
</sprite>
<sprite scale={[1.6, 2, 0]} position={[-1.2, -1.2, 0]}>
<spriteMaterial
attach="material"
map={rightArmTex}
visible={unlockedParts.rightArm}
visible={unlockedParts.right_arm}
/>
</sprite>
<sprite scale={[1.9, 1, 0]} position={[-1, -2.2, 0]}>
<spriteMaterial
attach="material"
map={rightLegTex}
visible={unlockedParts.rightLeg}
visible={unlockedParts.right_leg}
/>
</sprite>
</>

View file

@ -28,6 +28,7 @@ const setNodeViewed = useStore.getState().setNodeViewed;
const resetMediaScene = useStore.getState().resetMediaScene;
const incrementSsknLvl = useStore.getState().incrementSsknLvl;
const loadUserSaveState = useStore.getState().loadUserSaveState;
const restartGameState = useStore.getState().restartGameState;
export const siteMoveHorizontal = (calculatedState: {
lainMoveAnimation: string;
@ -725,11 +726,12 @@ export const exitUserAuthorization = {
audio: [{ sfx: [audio.sound29] }],
};
// todo reset state
export const startNewGame = {
state: [
{ mutation: { currentScene: "main", intro: true, inputCooldown: -1 } },
],
effects: [restartGameState],
};
export const updatePlayerName = (calculatedState: { playerName: string }) => ({

View file

@ -2,6 +2,14 @@
"sskn_level": 0,
"gate_level": 0,
"final_video_viewcount": 0,
"polytan_unlocked_parts": {
"body": false,
"head": false,
"left_arm": false,
"right_arm": false,
"left_leg": false,
"right_leg": false
},
"nodes": {
"Cou001": {
"is_viewed": 0

View file

@ -19,13 +19,13 @@ const PolytanScene = () => {
case 6:
return "head";
case 5:
return "rightArm";
return "right_arm";
case 4:
return "leftArm";
return "left_arm";
case 3:
return "rightLeg";
return "right_leg";
case 2:
return "leftLeg";
return "left_leg";
case 1:
return "body";
}

View file

@ -23,7 +23,6 @@ import {
NodeAttributes,
NodeData,
PauseComponent,
PolytanBodyParts,
PromptComponent,
RightMediaComponent,
SiteSaveState,
@ -90,8 +89,6 @@ type State = {
activeSsknComponent: SsknComponent;
ssknLoading: boolean;
polytanUnlockedParts: PolytanBodyParts;
playerName: string;
activeMainMenuComponent: MainMenuComponent;
@ -198,16 +195,6 @@ export const useStore = create(
activeSsknComponent: "ok",
ssknLoading: false,
// polytan scene
polytanUnlockedParts: {
body: false,
head: false,
leftArm: false,
rightArm: false,
leftLeg: false,
rightLeg: false,
},
// player name
playerName: "",
@ -312,12 +299,18 @@ export const useStore = create(
setWordSelected: (to: boolean) => set(() => ({ wordSelected: to })),
setPolytanPartUnlocked: (bodyPart: string) =>
set((state) => ({
polytanUnlockedParts: {
...state.polytanUnlockedParts,
set((state) => {
const polytanParts = {
...state.gameProgress.polytan_unlocked_parts,
[bodyPart]: true,
},
})),
};
return {
gameProgress: {
...state.gameProgress,
polytan_unlocked_parts: polytanParts,
},
};
}),
setInputCooldown: (to: number) => set(() => ({ inputCooldown: to })),
@ -345,7 +338,36 @@ export const useStore = create(
activeSite: userState.activeSite,
gameProgress: userState.gameProgress,
playerName: userState.playerName,
polytanUnlockedParts: userState.polytanUnlockedParts,
})),
restartGameState: () =>
set(() => ({
siteSaveState: {
a: {
activeNode: {
...getNodeById("0414", "a"),
matrixIndices: { matrixIdx: 7, rowIdx: 1, colIdx: 0 },
},
siteRot: [0, 0, 0],
activeLevel: "04",
},
b: {
activeNode: {
...getNodeById("0105", "b"),
matrixIndices: { matrixIdx: 6, rowIdx: 2, colIdx: 0 },
},
siteRot: [0, 0 - Math.PI / 4, 0],
activeLevel: "01",
},
},
activeNode: {
...site_a["04"]["0414"],
matrixIndices: { matrixIdx: 7, rowIdx: 1, colIdx: 0 },
},
siteRot: [0, 0, 0],
activeLevel: "04",
activeSite: "a",
gameProgress: game_progress,
})),
})
)
@ -441,7 +463,6 @@ export const getCurrentUserState = (): UserSaveState => {
activeSite: state.activeSite,
gameProgress: state.gameProgress,
playerName: state.playerName,
polytanUnlockedParts: state.polytanUnlockedParts,
};
};
@ -449,7 +470,8 @@ export const saveUserProgress = (state: UserSaveState) =>
localStorage.setItem("lainSaveState", JSON.stringify(state));
export const isPolytanFullyUnlocked = () => {
const polytanProgress = useStore.getState().polytanUnlockedParts;
const polytanProgress = useStore.getState().gameProgress
.polytan_unlocked_parts;
for (const key in polytanProgress)
if (!polytanProgress[key as keyof typeof polytanProgress]) return false;

View file

@ -87,15 +87,6 @@ export type BootSubscene = "main_menu" | "load_data" | "authorize_user";
export type PromptComponent = "yes" | "no";
export type PolytanBodyParts = {
body: boolean;
head: boolean;
leftArm: boolean;
rightArm: boolean;
leftLeg: boolean;
rightLeg: boolean;
};
type PromptContext = {
activePromptComponent: PromptComponent;
promptVisible: boolean;
@ -207,5 +198,4 @@ export type UserSaveState = {
activeSite: ActiveSite;
gameProgress: GameProgress;
playerName: string;
polytanUnlockedParts: PolytanBodyParts;
};