mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-29 01:36:47 +08:00
add: mode & character page
This commit is contained in:
@@ -11,12 +11,18 @@ import type { Talent } from '@remake/data/talent'
|
||||
export enum Step {
|
||||
Idle = 'idle',
|
||||
Mode = 'mode',
|
||||
Chara = 'chara',
|
||||
Pick = 'pick',
|
||||
Alloc = 'alloc',
|
||||
Play = 'play',
|
||||
Summary = 'summary',
|
||||
}
|
||||
|
||||
export enum Mode {
|
||||
Classic = 'classic',
|
||||
Celebrity = 'celebrity',
|
||||
}
|
||||
|
||||
export type Log = Omit<NextResult, 'state'> & {
|
||||
props: Omit<Properties, 'age'>
|
||||
}
|
||||
@@ -47,8 +53,8 @@ export const useGameReset = () => {
|
||||
}, [resetTalent, resetAlloc, resetState, resetLogs])
|
||||
}
|
||||
|
||||
export const useStep = () => useAtomValue(stepAtom)
|
||||
export const useSetStep = () => useSetAtom(stepAtom)
|
||||
export const useStep = () => [useAtomValue(stepAtom), Step] as const
|
||||
export const useSetStep = () => [useSetAtom(stepAtom), Step] as const
|
||||
export const useGameState = () => useAtomValue(gameStateAtom)
|
||||
export const useSummary = () => useAtomValue(summaryAtom)
|
||||
export const useLogs = () => useAtomValue(logsAtom)
|
||||
@@ -64,6 +70,24 @@ export const useRemake = () => {
|
||||
}, [mode, times, setStep, reset])
|
||||
}
|
||||
|
||||
export const useModeChoose = () => {
|
||||
const setStep = useSetAtom(stepAtom)
|
||||
const choose = useCallback(
|
||||
(mode: Mode) => {
|
||||
switch (mode) {
|
||||
case Mode.Classic:
|
||||
setStep(Step.Pick)
|
||||
break
|
||||
case Mode.Celebrity:
|
||||
setStep(Step.Chara)
|
||||
break
|
||||
}
|
||||
},
|
||||
[setStep],
|
||||
)
|
||||
return [Mode, choose] as const
|
||||
}
|
||||
|
||||
export const useStart = () => {
|
||||
const { spirit } = useConfig()
|
||||
const [profile] = useProfile()
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useState, useCallback } from 'react'
|
||||
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
|
||||
import { useConfig } from './config'
|
||||
import { useProfile } from './profile'
|
||||
import { useSetStep, Step } from './play'
|
||||
import { useSetStep } from './play'
|
||||
import { pull, exclude, talentsPicked } from '@remake/core'
|
||||
import type { TalentsPickedResult, RNG } from '@remake/core'
|
||||
import type { Talent } from '@remake/data/talent'
|
||||
@@ -93,13 +93,13 @@ export const useTalentSubmit = () => {
|
||||
const picked = useAtomValue(pickedAtom)
|
||||
const setReplaced = useSetAtom(replacedAtom)
|
||||
const { enabled } = useSubmitIsEnable()
|
||||
const next = useSetStep()
|
||||
const [setStep, Step] = useSetStep()
|
||||
return useCallback(
|
||||
(rng?: RNG) => {
|
||||
if (!enabled) throw new Error('Not enough talents picked')
|
||||
setReplaced(talentsPicked(picked, rng))
|
||||
next(Step.Alloc)
|
||||
setStep(Step.Alloc)
|
||||
},
|
||||
[enabled, picked, setReplaced, next],
|
||||
[enabled, picked, setReplaced, setStep],
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user