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
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
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
MyCard
Neos
Commits
36777d2f
Commit
36777d2f
authored
Oct 17, 2022
by
chechunchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add redux
parent
bfe59ab4
Pipeline
#17226
failed with stage
in 2 minutes and 8 seconds
Changes
8
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
2252 additions
and
1621 deletions
+2252
-1621
package-lock.json
package-lock.json
+244
-0
package.json
package.json
+3
-0
src/App.tsx
src/App.tsx
+1
-1
src/api/idl/ocgcore.ts
src/api/idl/ocgcore.ts
+1948
-1604
src/main.tsx
src/main.tsx
+5
-1
src/reducers/joinSlice.ts
src/reducers/joinSlice.ts
+19
-0
src/store.ts
src/store.ts
+11
-0
src/ui/WaitRoom.tsx
src/ui/WaitRoom.tsx
+21
-15
No files found.
package-lock.json
View file @
36777d2f
This diff is collapsed.
Click to expand it.
package.json
View file @
36777d2f
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
"version"
:
"0.1.0"
,
"version"
:
"0.1.0"
,
"private"
:
true
,
"private"
:
true
,
"dependencies"
:
{
"dependencies"
:
{
"
@reduxjs/toolkit
"
:
"
^1.8.6
"
,
"
@testing-library/jest-dom
"
:
"
^5.16.5
"
,
"
@testing-library/jest-dom
"
:
"
^5.16.5
"
,
"
@testing-library/react
"
:
"
^13.3.0
"
,
"
@testing-library/react
"
:
"
^13.3.0
"
,
"
@testing-library/user-event
"
:
"
^13.5.0
"
,
"
@testing-library/user-event
"
:
"
^13.5.0
"
,
...
@@ -10,10 +11,12 @@
...
@@ -10,10 +11,12 @@
"
@types/node
"
:
"
^16.11.48
"
,
"
@types/node
"
:
"
^16.11.48
"
,
"
@types/react
"
:
"
^18.0.17
"
,
"
@types/react
"
:
"
^18.0.17
"
,
"
@types/react-dom
"
:
"
^18.0.6
"
,
"
@types/react-dom
"
:
"
^18.0.6
"
,
"
@types/react-redux
"
:
"
^7.1.24
"
,
"
axios
"
:
"
^0.27.2
"
,
"
axios
"
:
"
^0.27.2
"
,
"
google-protobuf
"
:
"
^3.21.0
"
,
"
google-protobuf
"
:
"
^3.21.0
"
,
"
react
"
:
"
^18.2.0
"
,
"
react
"
:
"
^18.2.0
"
,
"
react-dom
"
:
"
^18.2.0
"
,
"
react-dom
"
:
"
^18.2.0
"
,
"
react-redux
"
:
"
^8.0.4
"
,
"
react-router-dom
"
:
"
^6.4.0
"
,
"
react-router-dom
"
:
"
^6.4.0
"
,
"
react-scripts
"
:
"
^5.0.1
"
,
"
react-scripts
"
:
"
^5.0.1
"
,
"
socket.io-client
"
:
"
^4.5.1
"
,
"
socket.io-client
"
:
"
^4.5.1
"
,
...
...
src/App.tsx
View file @
36777d2f
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
JoinRoom
from
"
./JoinRoom
"
;
import
JoinRoom
from
"
./JoinRoom
"
;
import
WaitRoom
from
"
./WaitRoom
"
;
import
WaitRoom
from
"
./
ui//
WaitRoom
"
;
import
ThreeJs
from
"
./ThreeJs
"
;
import
ThreeJs
from
"
./ThreeJs
"
;
import
{
Routes
,
Route
}
from
"
react-router-dom
"
;
import
{
Routes
,
Route
}
from
"
react-router-dom
"
;
...
...
src/api/idl/ocgcore.ts
View file @
36777d2f
This diff is collapsed.
Click to expand it.
src/main.tsx
View file @
36777d2f
...
@@ -3,6 +3,8 @@ import ReactDOM from "react-dom/client";
...
@@ -3,6 +3,8 @@ import ReactDOM from "react-dom/client";
import
App
from
"
./App
"
;
import
App
from
"
./App
"
;
import
reportWebVitals
from
"
./reportWebVitals
"
;
import
reportWebVitals
from
"
./reportWebVitals
"
;
import
{
BrowserRouter
}
from
"
react-router-dom
"
;
import
{
BrowserRouter
}
from
"
react-router-dom
"
;
import
{
Provider
}
from
"
react-redux
"
;
import
{
store
}
from
"
./store
"
;
const
root
=
ReactDOM
.
createRoot
(
const
root
=
ReactDOM
.
createRoot
(
document
.
getElementById
(
"
root
"
)
as
HTMLElement
document
.
getElementById
(
"
root
"
)
as
HTMLElement
...
@@ -10,7 +12,9 @@ const root = ReactDOM.createRoot(
...
@@ -10,7 +12,9 @@ const root = ReactDOM.createRoot(
root
.
render
(
root
.
render
(
<
React
.
StrictMode
>
<
React
.
StrictMode
>
<
BrowserRouter
>
<
BrowserRouter
>
<
Provider
store=
{
store
}
>
<
App
/>
<
App
/>
</
Provider
>
</
BrowserRouter
>
</
BrowserRouter
>
</
React
.
StrictMode
>
</
React
.
StrictMode
>
);
);
...
...
src/reducers/joinSlice.ts
0 → 100644
View file @
36777d2f
import
{
createSlice
}
from
"
@reduxjs/toolkit
"
;
const
initialState
=
false
;
const
joinedSlice
=
createSlice
({
name
:
"
join
"
,
initialState
,
reducers
:
{
setJoined
(
state
)
{
state
=
true
;
},
setUnJoined
(
state
)
{
state
=
false
;
},
},
});
export
const
{
setJoined
,
setUnJoined
}
=
joinedSlice
.
actions
;
export
default
joinedSlice
.
reducer
;
src/store.ts
0 → 100644
View file @
36777d2f
import
{
configureStore
}
from
"
@reduxjs/toolkit
"
;
import
joinedReducer
from
"
./reducers/joinSlice
"
;
export
const
store
=
configureStore
({
reducer
:
{
join
:
joinedReducer
,
},
});
export
type
RootState
=
ReturnType
<
typeof
store
.
getState
>
;
export
type
AppDispatch
=
typeof
store
.
dispatch
;
src/WaitRoom.tsx
→
src/
ui/
WaitRoom.tsx
View file @
36777d2f
import
React
,
{
useRef
,
useEffect
,
useState
,
useReducer
}
from
"
react
"
;
import
React
,
{
useRef
,
useEffect
,
useState
,
useReducer
}
from
"
react
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
{
ygopro
}
from
"
./api/idl/ocgcore
"
;
import
{
ygopro
}
from
"
../api/idl/ocgcore
"
;
import
{
fetchDeck
,
IDeck
}
from
"
./Card
"
;
import
{
fetchDeck
,
IDeck
}
from
"
../Card
"
;
import
"
./css/WaitRoom.css
"
;
import
"
../css/WaitRoom.css
"
;
import
{
useDispatch
,
useSelector
}
from
"
react-redux
"
;
import
{
setJoined
}
from
"
../reducers/joinSlice
"
;
type
Player
=
{
type
Player
=
{
name
?:
string
;
name
?:
string
;
...
@@ -20,17 +22,18 @@ export default function WaitRoom() {
...
@@ -20,17 +22,18 @@ export default function WaitRoom() {
ip
?:
string
;
ip
?:
string
;
}
>
();
}
>
();
const
[
joined
,
setJoined
]
=
useState
<
boolean
>
(
false
);
const
[
chat
,
setChat
]
=
useState
<
string
>
(
""
);
const
[
chat
,
setChat
]
=
useState
<
string
>
(
""
);
const
[
choseDeck
,
setChoseDeck
]
=
useState
<
boolean
>
(
false
);
const
[
choseDeck
,
setChoseDeck
]
=
useState
<
boolean
>
(
false
);
const
[
observerCount
,
setObserverCount
]
=
useState
<
number
>
(
0
);
const
[
observerCount
,
setObserverCount
]
=
useState
<
number
>
(
0
);
const
[
player0
,
setPlayer0
]
=
useState
<
Player
>
({});
const
[
player0
,
setPlayer0
]
=
useState
<
Player
>
({});
const
[
player1
,
setPlayer1
]
=
useState
<
Player
>
({});
const
[
player1
,
setPlayer1
]
=
useState
<
Player
>
({});
const
[
isHost
,
setIsHost
]
=
useState
<
boolean
>
(
false
);
const
[
isHost
,
setIsHost
]
=
useState
<
boolean
>
(
false
);
const
[
_
,
forceUpdate
]
=
useReducer
(
x
=>
x
+
1
,
0
);
// todo: use correct update design
const
[
_
,
forceUpdate
]
=
useReducer
(
(
x
)
=>
x
+
1
,
0
);
// todo: use correct update design
const
ws
=
useRef
<
WebSocket
|
null
>
(
null
);
const
ws
=
useRef
<
WebSocket
|
null
>
(
null
);
const
dispatch
=
useDispatch
();
const
{
player
,
passWd
,
ip
}
=
params
;
const
{
player
,
passWd
,
ip
}
=
params
;
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -61,14 +64,15 @@ export default function WaitRoom() {
...
@@ -61,14 +64,15 @@ export default function WaitRoom() {
console
.
log
(
"
Websocket closed
"
);
console
.
log
(
"
Websocket closed
"
);
};
};
ws
.
current
.
onmessage
=
e
=>
{
ws
.
current
.
onmessage
=
(
e
)
=>
{
const
pb
=
ygopro
.
YgoStocMsg
.
deserializeBinary
(
e
.
data
);
const
pb
=
ygopro
.
YgoStocMsg
.
deserializeBinary
(
e
.
data
);
switch
(
pb
.
msg
)
{
switch
(
pb
.
msg
)
{
case
"
stoc_join_game
"
:
{
case
"
stoc_join_game
"
:
{
const
msg
=
pb
.
stoc_join_game
;
const
msg
=
pb
.
stoc_join_game
;
// todo
// todo
setJoined
(
true
);
dispatch
(
setJoined
());
break
;
break
;
}
}
case
"
stoc_chat
"
:
{
case
"
stoc_chat
"
:
{
...
@@ -225,6 +229,8 @@ export default function WaitRoom() {
...
@@ -225,6 +229,8 @@ export default function WaitRoom() {
};
};
},
[
ws
]);
},
[
ws
]);
const
joined
=
useSelector
((
state
)
=>
state
);
const
handleChoseDeck
=
async
()
=>
{
const
handleChoseDeck
=
async
()
=>
{
if
(
ws
.
current
)
{
if
(
ws
.
current
)
{
const
deck
=
await
fetchDeck
(
"
hero.ydk
"
);
const
deck
=
await
fetchDeck
(
"
hero.ydk
"
);
...
@@ -298,8 +304,8 @@ export default function WaitRoom() {
...
@@ -298,8 +304,8 @@ export default function WaitRoom() {
function
sendPlayerInfo
(
ws
:
WebSocket
,
player
:
string
)
{
function
sendPlayerInfo
(
ws
:
WebSocket
,
player
:
string
)
{
const
playerInfo
=
new
ygopro
.
YgoCtosMsg
({
const
playerInfo
=
new
ygopro
.
YgoCtosMsg
({
ctos_player_info
:
new
ygopro
.
CtosPlayerInfo
({
ctos_player_info
:
new
ygopro
.
CtosPlayerInfo
({
name
:
player
name
:
player
,
})
})
,
});
});
ws
.
send
(
playerInfo
.
serialize
());
ws
.
send
(
playerInfo
.
serialize
());
...
@@ -310,8 +316,8 @@ function sendJoinGame(ws: WebSocket, version: number, passWd: string) {
...
@@ -310,8 +316,8 @@ function sendJoinGame(ws: WebSocket, version: number, passWd: string) {
ctos_join_game
:
new
ygopro
.
CtosJoinGame
({
ctos_join_game
:
new
ygopro
.
CtosJoinGame
({
version
,
// todo: use config
version
,
// todo: use config
gameid
:
0
,
gameid
:
0
,
passwd
:
passWd
passwd
:
passWd
,
})
})
,
});
});
ws
.
send
(
joinGame
.
serialize
());
ws
.
send
(
joinGame
.
serialize
());
...
@@ -322,8 +328,8 @@ function sendUpdateDeck(ws: WebSocket, deck: IDeck) {
...
@@ -322,8 +328,8 @@ function sendUpdateDeck(ws: WebSocket, deck: IDeck) {
ctos_update_deck
:
new
ygopro
.
CtosUpdateDeck
({
ctos_update_deck
:
new
ygopro
.
CtosUpdateDeck
({
main
:
deck
.
main
,
main
:
deck
.
main
,
extra
:
deck
.
extra
,
extra
:
deck
.
extra
,
side
:
deck
.
side
side
:
deck
.
side
,
})
})
,
});
});
ws
.
send
(
updateDeck
.
serialize
());
ws
.
send
(
updateDeck
.
serialize
());
...
@@ -331,7 +337,7 @@ function sendUpdateDeck(ws: WebSocket, deck: IDeck) {
...
@@ -331,7 +337,7 @@ function sendUpdateDeck(ws: WebSocket, deck: IDeck) {
function
sendHsReady
(
ws
:
WebSocket
)
{
function
sendHsReady
(
ws
:
WebSocket
)
{
const
hasReady
=
new
ygopro
.
YgoCtosMsg
({
const
hasReady
=
new
ygopro
.
YgoCtosMsg
({
ctos_hs_ready
:
new
ygopro
.
CtosHsReady
({})
ctos_hs_ready
:
new
ygopro
.
CtosHsReady
({})
,
});
});
ws
.
send
(
hasReady
.
serialize
());
ws
.
send
(
hasReady
.
serialize
());
...
@@ -339,7 +345,7 @@ function sendHsReady(ws: WebSocket) {
...
@@ -339,7 +345,7 @@ function sendHsReady(ws: WebSocket) {
function
sendHsStart
(
ws
:
WebSocket
)
{
function
sendHsStart
(
ws
:
WebSocket
)
{
const
hasStart
=
new
ygopro
.
YgoCtosMsg
({
const
hasStart
=
new
ygopro
.
YgoCtosMsg
({
ctos_hs_start
:
new
ygopro
.
CtosHsStart
({})
ctos_hs_start
:
new
ygopro
.
CtosHsStart
({})
,
});
});
ws
.
send
(
hasStart
.
serialize
());
ws
.
send
(
hasStart
.
serialize
());
...
...
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