Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baichixing
Neos
Commits
100e9f96
Commit
100e9f96
authored
Apr 16, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: valtio store logic
parent
4b3fa376
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
85 additions
and
13 deletions
+85
-13
src/main.tsx
src/main.tsx
+1
-1
src/service/mora/deckCount.ts
src/service/mora/deckCount.ts
+14
-0
src/service/mora/selectHand.ts
src/service/mora/selectHand.ts
+1
-1
src/service/mora/selectTp.ts
src/service/mora/selectTp.ts
+2
-0
src/service/room/chat.ts
src/service/room/chat.ts
+1
-1
src/service/room/duelStart.ts
src/service/room/duelStart.ts
+3
-0
src/service/room/hsPlayerChange.ts
src/service/room/hsPlayerChange.ts
+8
-2
src/service/room/hsPlayerEnter.ts
src/service/room/hsPlayerEnter.ts
+1
-1
src/service/room/hsWatchChange.ts
src/service/room/hsWatchChange.ts
+2
-0
src/service/room/joinGame.ts
src/service/room/joinGame.ts
+4
-0
src/service/room/typeChange.ts
src/service/room/typeChange.ts
+9
-0
src/ui/Duel/Message/TimeLine.tsx
src/ui/Duel/Message/TimeLine.tsx
+8
-1
src/ui/Duel/Message/timeLine.tsx
src/ui/Duel/Message/timeLine.tsx
+8
-1
src/ui/Mora.tsx
src/ui/Mora.tsx
+9
-2
src/ui/WaitRoom.tsx
src/ui/WaitRoom.tsx
+12
-1
src/valtioStores/chatStore.ts
src/valtioStores/chatStore.ts
+0
-0
src/valtioStores/index.tsx
src/valtioStores/index.tsx
+2
-2
src/valtioStores/joinStore.ts
src/valtioStores/joinStore.ts
+0
-0
src/valtioStores/moraStore.ts
src/valtioStores/moraStore.ts
+0
-0
src/valtioStores/playerStore.ts
src/valtioStores/playerStore.ts
+0
-0
No files found.
src/main.tsx
View file @
100e9f96
...
...
@@ -26,7 +26,7 @@ import ReactDOM from "react-dom/client";
import
{
Provider
}
from
"
react-redux
"
;
import
{
BrowserRouter
}
from
"
react-router-dom
"
;
import
{
ValtioProvider
}
from
"
@/
s
tores
"
;
import
{
ValtioProvider
}
from
"
@/
valtioS
tores
"
;
import
{
store
}
from
"
./store
"
;
import
Neos
from
"
./ui/Neos
"
;
...
...
src/service/mora/deckCount.ts
View file @
100e9f96
...
...
@@ -2,6 +2,8 @@ import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import
{
player0DeckInfo
,
player1DeckInfo
}
from
"
@/reducers/playerSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
playerStore
}
from
"
@/valtioStores
"
;
// FIXME: player0 不一定是当前玩家
export
default
function
handleDeckCount
(
pb
:
ygopro
.
YgoStocMsg
)
{
const
dispath
=
store
.
dispatch
;
...
...
@@ -15,6 +17,12 @@ export default function handleDeckCount(pb: ygopro.YgoStocMsg) {
})
);
playerStore
.
player0
.
deckInfo
=
{
mainCnt
:
deckCount
.
meMain
,
extraCnt
:
deckCount
.
meExtra
,
sideCnt
:
deckCount
.
meSide
,
};
dispath
(
player1DeckInfo
({
mainCnt
:
deckCount
.
opMain
,
...
...
@@ -22,4 +30,10 @@ export default function handleDeckCount(pb: ygopro.YgoStocMsg) {
sideCnt
:
deckCount
.
opSide
,
})
);
playerStore
.
player1
.
deckInfo
=
{
mainCnt
:
deckCount
.
opMain
,
extraCnt
:
deckCount
.
opExtra
,
sideCnt
:
deckCount
.
opSide
,
};
}
src/service/mora/selectHand.ts
View file @
100e9f96
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
selectHandAble
}
from
"
@/reducers/moraSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
moraStore
}
from
"
@/
s
tores
"
;
import
{
moraStore
}
from
"
@/
valtioS
tores
"
;
export
default
function
handleSelectHand
(
_
:
ygopro
.
YgoStocMsg
)
{
const
dispatch
=
store
.
dispatch
;
...
...
src/service/mora/selectTp.ts
View file @
100e9f96
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
selectTpAble
}
from
"
@/reducers/moraSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
moraStore
}
from
"
@/valtioStores
"
;
export
default
function
handleSelectTp
(
_
:
ygopro
.
YgoStocMsg
)
{
const
dispatch
=
store
.
dispatch
;
dispatch
(
selectTpAble
());
moraStore
.
selectTpAble
=
true
;
}
src/service/room/chat.ts
View file @
100e9f96
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
postChat
}
from
"
@/reducers/chatSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
chatStore
}
from
"
@/
s
tores
"
;
import
{
chatStore
}
from
"
@/
valtioS
tores
"
;
export
default
function
handleChat
(
pb
:
ygopro
.
YgoStocMsg
)
{
const
dispatch
=
store
.
dispatch
;
...
...
src/service/room/duelStart.ts
View file @
100e9f96
...
...
@@ -2,8 +2,11 @@ import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import
{
duelStart
}
from
"
@/reducers/moraSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
moraStore
}
from
"
@/valtioStores
"
;
export
default
function
handleDuelStart
(
_pb
:
ygopro
.
YgoStocMsg
)
{
const
dispatch
=
store
.
dispatch
;
dispatch
(
duelStart
());
moraStore
.
duelStart
=
true
;
}
src/service/room/hsPlayerChange.ts
View file @
100e9f96
...
...
@@ -6,6 +6,7 @@ import {
player1Leave
,
player1Update
,
}
from
"
@/reducers/playerSlice
"
;
import
{
playerStore
}
from
"
@/valtioStores
"
;
import
{
store
}
from
"
@/store
"
;
const
READY_STATE
=
"
ready
"
;
...
...
@@ -48,25 +49,30 @@ export default function handleHsPlayerChange(pb: ygopro.YgoStocMsg) {
change
.
pos
==
0
?
dispatch
(
player0Update
(
READY_STATE
))
:
dispatch
(
player1Update
(
READY_STATE
));
playerStore
[
change
.
pos
==
0
?
"
player0
"
:
"
player1
"
].
state
=
READY_STATE
;
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
NO_READY
:
{
change
.
pos
==
0
?
dispatch
(
player0Update
(
NO_READY_STATE
))
:
dispatch
(
player1Update
(
NO_READY_STATE
));
playerStore
[
change
.
pos
==
0
?
"
player0
"
:
"
player1
"
].
state
=
NO_READY_STATE
;
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
LEAVE
:
{
change
.
pos
==
0
?
dispatch
(
player0Leave
)
:
dispatch
(
player1Leave
);
playerStore
[
change
.
pos
==
0
?
"
player0
"
:
"
player1
"
]
=
{};
break
;
}
case
ygopro
.
StocHsPlayerChange
.
State
.
TO_OBSERVER
:
{
change
.
pos
==
0
?
dispatch
(
player0Leave
)
:
dispatch
(
player1Leave
);
dispatch
(
observerIncrement
());
playerStore
[
change
.
pos
==
0
?
"
player0
"
:
"
player1
"
]
=
{};
// todo: 有没有必要?
playerStore
.
observerCount
+=
1
;
break
;
}
default
:
{
...
...
src/service/room/hsPlayerEnter.ts
View file @
100e9f96
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
player0Enter
,
player1Enter
}
from
"
@/reducers/playerSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
playerStore
}
from
"
@/
s
tores
"
;
import
{
playerStore
}
from
"
@/
valtioS
tores
"
;
export
default
function
handleHsPlayerEnter
(
pb
:
ygopro
.
YgoStocMsg
)
{
const
dispatch
=
store
.
dispatch
;
...
...
src/service/room/hsWatchChange.ts
View file @
100e9f96
import
{
ygopro
}
from
"
@/api/ocgcore/idl/ocgcore
"
;
import
{
observerChange
}
from
"
@/reducers/playerSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
playerStore
}
from
"
@/valtioStores
"
;
export
default
function
handleHsWatchChange
(
pb
:
ygopro
.
YgoStocMsg
)
{
const
dispatch
=
store
.
dispatch
;
const
count
=
pb
.
stoc_hs_watch_change
.
count
;
dispatch
(
observerChange
(
count
));
playerStore
.
observerCount
=
count
;
}
src/service/room/joinGame.ts
View file @
100e9f96
...
...
@@ -2,10 +2,14 @@ import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import
{
setJoined
}
from
"
@/reducers/joinSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
joinStore
}
from
"
@/valtioStores
"
;
export
default
function
handleJoinGame
(
pb
:
ygopro
.
YgoStocMsg
)
{
const
dispatch
=
store
.
dispatch
;
const
msg
=
pb
.
stoc_join_game
;
// todo
dispatch
(
setJoined
());
joinStore
.
value
=
true
;
}
src/service/room/typeChange.ts
View file @
100e9f96
...
...
@@ -6,6 +6,7 @@ import {
updateIsHost
,
}
from
"
@/reducers/playerSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
playerStore
}
from
"
@/valtioStores
"
;
const
NO_READY_STATE
=
"
not ready
"
;
...
...
@@ -22,12 +23,20 @@ export default function handleTypeChange(pb: ygopro.YgoStocMsg) {
dispatch
(
hostChange
(
0
));
dispatch
(
player0Update
(
NO_READY_STATE
));
playerStore
.
player0
.
isHost
=
true
;
playerStore
.
player1
.
isHost
=
false
;
playerStore
.
player0
.
state
=
NO_READY_STATE
;
break
;
}
case
ygopro
.
StocTypeChange
.
SelfType
.
PLAYER2
:
{
dispatch
(
hostChange
(
0
));
dispatch
(
player1Update
(
NO_READY_STATE
));
playerStore
.
player0
.
isHost
=
false
;
playerStore
.
player1
.
isHost
=
true
;
playerStore
.
player1
.
state
=
NO_READY_STATE
;
break
;
}
default
:
{
...
...
src/ui/Duel/Message/TimeLine.tsx
View file @
100e9f96
import
{
MessageOutlined
}
from
"
@ant-design/icons
"
;
import
{
Timeline
,
TimelineItemProps
}
from
"
antd
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
,
useContext
}
from
"
react
"
;
import
{
useAppSelector
}
from
"
@/hook
"
;
import
{
selectChat
}
from
"
@/reducers/chatSlice
"
;
import
{
valtioContext
}
from
"
@/valtioStores
"
;
import
{
useSnapshot
}
from
"
valtio
"
;
export
const
DuelTimeLine
=
()
=>
{
const
[
items
,
setItems
]
=
useState
<
TimelineItemProps
[]
>
([]);
const
chat
=
useAppSelector
(
selectChat
);
const
stateChat
=
useContext
(
valtioContext
).
chatStore
;
const
snapChat
=
useSnapshot
(
stateChat
);
// const chat = snapChat.message;
useEffect
(()
=>
{
setItems
((
prev
)
=>
prev
.
concat
([
...
...
src/ui/Duel/Message/timeLine.tsx
View file @
100e9f96
import
{
MessageOutlined
}
from
"
@ant-design/icons
"
;
import
{
Timeline
,
TimelineItemProps
}
from
"
antd
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
,
useContext
}
from
"
react
"
;
import
{
useAppSelector
}
from
"
@/hook
"
;
import
{
selectChat
}
from
"
@/reducers/chatSlice
"
;
import
{
valtioContext
}
from
"
@/valtioStores
"
;
import
{
useSnapshot
}
from
"
valtio
"
;
export
const
DuelTimeLine
=
()
=>
{
const
[
items
,
setItems
]
=
useState
<
TimelineItemProps
[]
>
([]);
const
chat
=
useAppSelector
(
selectChat
);
const
stateChat
=
useContext
(
valtioContext
).
chatStore
;
const
snapChat
=
useSnapshot
(
stateChat
);
// const chat = snapChat.message;
useEffect
(()
=>
{
setItems
((
prev
)
=>
prev
.
concat
([
...
...
src/ui/Mora.tsx
View file @
100e9f96
...
...
@@ -18,7 +18,8 @@ import {
unSelectTpAble
,
}
from
"
@/reducers/moraSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
ValtioContext
}
from
"
@/stores
"
;
import
{
valtioContext
}
from
"
@/valtioStores
"
;
import
{
useSnapshot
}
from
"
valtio
"
;
const
{
automation
:
{
isAiMode
,
isAiFirst
},
...
...
@@ -26,12 +27,18 @@ const {
}
=
useConfig
();
const
Mora
=
()
=>
{
const
stateMora
=
useContext
(
ValtioContext
).
moraStore
;
const
stateMora
=
useContext
(
valtioContext
).
moraStore
;
const
snapMora
=
useSnapshot
(
stateMora
);
const
dispatch
=
store
.
dispatch
;
const
selectHandAble
=
useAppSelector
(
selectHandSelectAble
);
const
selectTpAble
=
useAppSelector
(
selectTpSelectAble
);
const
duelHsStart
=
useAppSelector
(
selectDuelHsStart
);
// const selectHandAble = snapMora.selectHandAble;
// const selectTpAble = snapMora.selectTpAble;
// const duelHsStart = snapMora.duelStart;
const
navigate
=
useNavigate
();
const
{
player
,
passWd
,
ip
}
=
useParams
<
{
player
?:
string
;
...
...
src/ui/WaitRoom.tsx
View file @
100e9f96
...
...
@@ -19,7 +19,7 @@ import {
Space
,
Upload
,
}
from
"
antd
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
,
useContext
}
from
"
react
"
;
import
{
useNavigate
,
useParams
}
from
"
react-router-dom
"
;
import
rustInit
from
"
rust-src
"
;
import
YGOProDeck
from
"
ygopro-deck-encode
"
;
...
...
@@ -45,6 +45,8 @@ import {
selectPlayer1
,
}
from
"
@/reducers/playerSlice
"
;
import
{
store
}
from
"
@/store
"
;
import
{
valtioContext
}
from
"
@/valtioStores
"
;
import
{
useSnapshot
}
from
"
valtio
"
;
const
NeosConfig
=
useConfig
();
...
...
@@ -56,6 +58,8 @@ const {
}
=
useConfig
();
const
WaitRoom
=
()
=>
{
const
state
=
useContext
(
valtioContext
);
const
snap
=
useSnapshot
(
state
);
const
params
=
useParams
<
{
player
?:
string
;
passWd
?:
string
;
...
...
@@ -108,6 +112,13 @@ const WaitRoom = () => {
const
duelStart
=
useAppSelector
(
selectDuelStart
);
const
[
api
,
contextHolder
]
=
notification
.
useNotification
();
// const joined = snap.joinStore.value;
// const chat = snap.chatStore.message;
// const isHost = snap.playerStore.isHost;
// const player0 = snap.playerStore.player0;
// const player1 = snap.playerStore.player1;
// const duelStart = snap.moraStore.duelStart;
// FIXME: 这些数据应该从`store`中获取
// TODO: 云卡组
const
decks
=
[...
DeckManager
.
keys
()].
map
((
deckName
)
=>
({
...
...
src/
s
tores/chatStore.ts
→
src/
valtioS
tores/chatStore.ts
View file @
100e9f96
File moved
src/
s
tores/index.tsx
→
src/
valtioS
tores/index.tsx
View file @
100e9f96
...
...
@@ -24,7 +24,7 @@ devtools(valtioStore, { name: "valtio store", enabled: true });
/**
* 在组件之中使用valtio store
*/
export
const
V
altioContext
=
createContext
<
typeof
valtioStore
>
({}
as
any
);
export
const
v
altioContext
=
createContext
<
typeof
valtioStore
>
({}
as
any
);
/**
* 包裹根节点,使得所有子组件都可以使用valtio store
...
...
@@ -34,6 +34,6 @@ export const ValtioProvider: React.FC<{ children: ReactNode }> = ({
})
=>
{
const
state
=
useRef
(
valtioStore
).
current
;
return
(
<
ValtioContext
.
Provider
value=
{
state
}
>
{
children
}
</
V
altioContext
.
Provider
>
<
valtioContext
.
Provider
value=
{
state
}
>
{
children
}
</
v
altioContext
.
Provider
>
);
};
src/
s
tores/joinStore.ts
→
src/
valtioS
tores/joinStore.ts
View file @
100e9f96
File moved
src/
s
tores/moraStore.ts
→
src/
valtioS
tores/moraStore.ts
View file @
100e9f96
File moved
src/
s
tores/playerStore.ts
→
src/
valtioS
tores/playerStore.ts
View file @
100e9f96
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment