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
e716ebd0
Commit
e716ebd0
authored
Oct 05, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add chose deck logic in WaitRoom.tsx
parent
a4c9a8a7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
51 deletions
+47
-51
src/App.tsx
src/App.tsx
+0
-2
src/Card.tsx
src/Card.tsx
+7
-43
src/WaitRoom.tsx
src/WaitRoom.tsx
+40
-6
No files found.
src/App.tsx
View file @
e716ebd0
...
...
@@ -4,7 +4,6 @@ import JoinRoom from "./JoinRoom";
import
WaitRoom
from
"
./WaitRoom
"
;
import
ThreeJs
from
"
./ThreeJs
"
;
import
{
Routes
,
Route
}
from
"
react-router-dom
"
;
import
Card
from
"
./Card
"
;
function
App
()
{
return
(
...
...
@@ -12,7 +11,6 @@ function App() {
<
Route
path=
"/"
element=
{
<
JoinRoom
/>
}
/>
<
Route
path=
"/:player/:passWd/:ip"
element=
{
<
WaitRoom
/>
}
/>
<
Route
path=
"/three.js"
element=
{
<
ThreeJs
/>
}
/>
<
Route
path=
"/card"
element=
{
<
Card
/>
}
/>
</
Routes
>
);
}
...
...
src/Card.tsx
View file @
e716ebd0
import
axios
from
"
axios
"
;
import
React
,
{
useState
,
useEffect
}
from
"
react
"
;
export
default
function
Card
()
{
const
[
data
,
setData
]
=
useState
<
IDeck
>
({});
useEffect
(()
=>
{
const
fetchCards
=
async
()
=>
{
const
res
=
await
axios
.
get
<
IDeck
>
("http://localhost:3030/deck/hero.ydk");
setData(res.data);
};
fetchCards();
}, []);
const mainCards = (data.main || []).map((item, index) =
>
(
<
li
key=
{
index
}
>
{
item
}
</
li
>
));
const extraCards = (data.extra || []).map((item, index) =
>
(
<
li
key=
{
index
}
>
{
item
}
</
li
>
));
const sideCards = (data.side || []).map((item, index) =
>
(
<
li
key=
{
index
}
>
{
item
}
</
li
>
));
return (
<
ul
>
<
li
>
main
<
ul
>
{
mainCards
}
</
ul
>
</
li
>
<
li
>
extra
<
ul
>
{
extraCards
}
</
ul
>
</
li
>
<
li
>
side
<
ul
>
{
sideCards
}
</
ul
>
</
li
>
</
ul
>
);
}
interface IDeck
{
export
interface
IDeck
{
main
?:
number
[];
extra
?:
number
[];
side
?:
number
[];
}
export
async
function
fetchDeck
(
deck
:
string
):
Promise
<
IDeck
>
{
const
res
=
await
axios
.
get
<
IDeck
>
("http://localhost:3030/deck/" + deck);
return res.data;
}
src/WaitRoom.tsx
View file @
e716ebd0
import
React
,
{
useRef
,
useEffect
,
useState
}
from
"
react
"
;
import
{
useParams
}
from
"
react-router-dom
"
;
import
{
ygopro
}
from
"
./api/idl/ocgcore
"
;
import
{
fetchDeck
,
IDeck
}
from
"
./Card
"
;
export
default
function
WaitRoom
()
{
const
params
=
useParams
<
{
...
...
@@ -9,8 +10,9 @@ export default function WaitRoom() {
ip
?:
string
;
}
>
();
const
[
joined
,
setJoined
]
=
useState
<
string
>
(
"
false
"
);
const
[
joined
,
setJoined
]
=
useState
<
boolean
>
(
false
);
const
[
chat
,
setChat
]
=
useState
<
string
>
(
""
);
const
[
choseDeck
,
setChoseDeck
]
=
useState
<
boolean
>
(
false
);
const
ws
=
useRef
<
WebSocket
|
null
>
(
null
);
...
...
@@ -49,10 +51,8 @@ export default function WaitRoom() {
switch
(
pb
.
msg
)
{
case
"
stoc_join_game
"
:
{
const
msg
=
pb
.
stoc_join_game
;
console
.
log
(
"
joinGame msg=
"
+
msg
);
setJoined
(
"
true
"
);
// todo
setJoined
(
true
);
break
;
}
case
"
stoc_chat
"
:
{
...
...
@@ -76,9 +76,31 @@ export default function WaitRoom() {
};
},
[
ws
]);
const
handleChoseDeck
=
async
()
=>
{
if
(
ws
.
current
)
{
const
deck
=
await
fetchDeck
(
"
hero.ydk
"
);
sendUpdateDeck
(
ws
.
current
,
deck
);
setChoseDeck
(
true
);
}
};
const
handleChoseReady
=
()
=>
{
if
(
ws
.
current
)
{
// todo
}
};
return
(
<
div
>
<
p
>
joined:
{
joined
}
</
p
>
<
p
>
joined:
{
joined
?
"
true
"
:
"
false
"
}
</
p
>
<
button
disabled=
{
!
joined
}
onClick=
{
handleChoseDeck
}
>
choose hero.ydk
</
button
>
<
button
disabled=
{
!
choseDeck
}
onClick=
{
handleChoseReady
}
>
ready
</
button
>
<
p
>
chat:
{
chat
}
</
p
>
</
div
>
);
...
...
@@ -105,3 +127,15 @@ function sendJoinGame(ws: WebSocket, version: number, passWd: string) {
ws
.
send
(
joinGame
.
serialize
());
}
function
sendUpdateDeck
(
ws
:
WebSocket
,
deck
:
IDeck
)
{
const
updateDeck
=
new
ygopro
.
YgoCtosMsg
({
ctos_update_deck
:
new
ygopro
.
CtosUpdateDeck
({
main
:
deck
.
main
,
extra
:
deck
.
extra
,
side
:
deck
.
side
})
});
ws
.
send
(
updateDeck
.
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