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
love_飞影
Neos
Commits
baffcd9b
Commit
baffcd9b
authored
Oct 05, 2022
by
Chunchi Che
Committed by
GitHub
Oct 05, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9 from DarkNeos/dev
Dev
parents
af753793
04484ceb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
134 additions
and
56 deletions
+134
-56
neos-protobuf
neos-protobuf
+1
-1
src/App.tsx
src/App.tsx
+0
-2
src/Card.tsx
src/Card.tsx
+7
-43
src/WaitRoom.tsx
src/WaitRoom.tsx
+48
-6
src/api/idl/ocgcore.ts
src/api/idl/ocgcore.ts
+78
-4
No files found.
neos-protobuf
@
1ca09b1d
Subproject commit
a54ddaec084aaf70a779f5a876d2e8554905625c
Subproject commit
1ca09b1d90b55e2c155f83781c8b2a5d2ee30a04
src/App.tsx
View file @
baffcd9b
...
...
@@ -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 @
baffcd9b
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 @
baffcd9b
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
)
{
sendHsReady
(
ws
.
current
);
}
};
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,23 @@ 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
());
}
function
sendHsReady
(
ws
:
WebSocket
)
{
const
hasReady
=
new
ygopro
.
YgoCtosMsg
({
ctos_hs_ready
:
new
ygopro
.
CtosHsReady
({})
});
ws
.
send
(
hasReady
.
serialize
());
}
src/api/idl/ocgcore.ts
View file @
baffcd9b
...
...
@@ -6,19 +6,27 @@
import
*
as
pb_1
from
"
google-protobuf
"
;
export
namespace
ygopro
{
export
class
YgoCtosMsg
extends
pb_1
.
Message
{
#
one_of_decls
:
number
[][]
=
[[
1
,
2
,
3
]];
#
one_of_decls
:
number
[][]
=
[[
1
,
2
,
3
,
4
]];
constructor
(
data
?:
any
[]
|
({}
&
(({
ctos_player_info
?:
CtosPlayerInfo
;
ctos_join_game
?:
never
;
ctos_update_deck
?:
never
;
ctos_hs_ready
?:
never
;
}
|
{
ctos_player_info
?:
never
;
ctos_join_game
?:
CtosJoinGame
;
ctos_update_deck
?:
never
;
ctos_hs_ready
?:
never
;
}
|
{
ctos_player_info
?:
never
;
ctos_join_game
?:
never
;
ctos_update_deck
?:
CtosUpdateDeck
;
ctos_hs_ready
?:
never
;
}
|
{
ctos_player_info
?:
never
;
ctos_join_game
?:
never
;
ctos_update_deck
?:
never
;
ctos_hs_ready
?:
CtosHsReady
;
}))))
{
super
();
pb_1
.
Message
.
initialize
(
this
,
Array
.
isArray
(
data
)
?
data
:
[],
0
,
-
1
,
[],
this
.
#
one_of_decls
);
...
...
@@ -32,6 +40,9 @@ export namespace ygopro {
if
(
"
ctos_update_deck
"
in
data
&&
data
.
ctos_update_deck
!=
undefined
)
{
this
.
ctos_update_deck
=
data
.
ctos_update_deck
;
}
if
(
"
ctos_hs_ready
"
in
data
&&
data
.
ctos_hs_ready
!=
undefined
)
{
this
.
ctos_hs_ready
=
data
.
ctos_hs_ready
;
}
}
}
get
ctos_player_info
()
{
...
...
@@ -61,21 +72,32 @@ export namespace ygopro {
get
has_ctos_update_deck
()
{
return
pb_1
.
Message
.
getField
(
this
,
3
)
!=
null
;
}
get
ctos_hs_ready
()
{
return
pb_1
.
Message
.
getWrapperField
(
this
,
CtosHsReady
,
4
)
as
CtosHsReady
;
}
set
ctos_hs_ready
(
value
:
CtosHsReady
)
{
pb_1
.
Message
.
setOneofWrapperField
(
this
,
4
,
this
.
#
one_of_decls
[
0
],
value
);
}
get
has_ctos_hs_ready
()
{
return
pb_1
.
Message
.
getField
(
this
,
4
)
!=
null
;
}
get
msg
()
{
const
cases
:
{
[
index
:
number
]:
"
none
"
|
"
ctos_player_info
"
|
"
ctos_join_game
"
|
"
ctos_update_deck
"
;
[
index
:
number
]:
"
none
"
|
"
ctos_player_info
"
|
"
ctos_join_game
"
|
"
ctos_update_deck
"
|
"
ctos_hs_ready
"
;
}
=
{
0
:
"
none
"
,
1
:
"
ctos_player_info
"
,
2
:
"
ctos_join_game
"
,
3
:
"
ctos_update_deck
"
3
:
"
ctos_update_deck
"
,
4
:
"
ctos_hs_ready
"
};
return
cases
[
pb_1
.
Message
.
computeOneofCase
(
this
,
[
1
,
2
,
3
])];
return
cases
[
pb_1
.
Message
.
computeOneofCase
(
this
,
[
1
,
2
,
3
,
4
])];
}
static
fromObject
(
data
:
{
ctos_player_info
?:
ReturnType
<
typeof
CtosPlayerInfo
.
prototype
.
toObject
>
;
ctos_join_game
?:
ReturnType
<
typeof
CtosJoinGame
.
prototype
.
toObject
>
;
ctos_update_deck
?:
ReturnType
<
typeof
CtosUpdateDeck
.
prototype
.
toObject
>
;
ctos_hs_ready
?:
ReturnType
<
typeof
CtosHsReady
.
prototype
.
toObject
>
;
}):
YgoCtosMsg
{
const
message
=
new
YgoCtosMsg
({});
if
(
data
.
ctos_player_info
!=
null
)
{
...
...
@@ -87,6 +109,9 @@ export namespace ygopro {
if
(
data
.
ctos_update_deck
!=
null
)
{
message
.
ctos_update_deck
=
CtosUpdateDeck
.
fromObject
(
data
.
ctos_update_deck
);
}
if
(
data
.
ctos_hs_ready
!=
null
)
{
message
.
ctos_hs_ready
=
CtosHsReady
.
fromObject
(
data
.
ctos_hs_ready
);
}
return
message
;
}
toObject
()
{
...
...
@@ -94,6 +119,7 @@ export namespace ygopro {
ctos_player_info
?:
ReturnType
<
typeof
CtosPlayerInfo
.
prototype
.
toObject
>
;
ctos_join_game
?:
ReturnType
<
typeof
CtosJoinGame
.
prototype
.
toObject
>
;
ctos_update_deck
?:
ReturnType
<
typeof
CtosUpdateDeck
.
prototype
.
toObject
>
;
ctos_hs_ready
?:
ReturnType
<
typeof
CtosHsReady
.
prototype
.
toObject
>
;
}
=
{};
if
(
this
.
ctos_player_info
!=
null
)
{
data
.
ctos_player_info
=
this
.
ctos_player_info
.
toObject
();
...
...
@@ -104,6 +130,9 @@ export namespace ygopro {
if
(
this
.
ctos_update_deck
!=
null
)
{
data
.
ctos_update_deck
=
this
.
ctos_update_deck
.
toObject
();
}
if
(
this
.
ctos_hs_ready
!=
null
)
{
data
.
ctos_hs_ready
=
this
.
ctos_hs_ready
.
toObject
();
}
return
data
;
}
serialize
():
Uint8Array
;
...
...
@@ -116,6 +145,8 @@ export namespace ygopro {
writer
.
writeMessage
(
2
,
this
.
ctos_join_game
,
()
=>
this
.
ctos_join_game
.
serialize
(
writer
));
if
(
this
.
has_ctos_update_deck
)
writer
.
writeMessage
(
3
,
this
.
ctos_update_deck
,
()
=>
this
.
ctos_update_deck
.
serialize
(
writer
));
if
(
this
.
has_ctos_hs_ready
)
writer
.
writeMessage
(
4
,
this
.
ctos_hs_ready
,
()
=>
this
.
ctos_hs_ready
.
serialize
(
writer
));
if
(
!
w
)
return
writer
.
getResultBuffer
();
}
...
...
@@ -134,6 +165,9 @@ export namespace ygopro {
case
3
:
reader
.
readMessage
(
message
.
ctos_update_deck
,
()
=>
message
.
ctos_update_deck
=
CtosUpdateDeck
.
deserialize
(
reader
));
break
;
case
4
:
reader
.
readMessage
(
message
.
ctos_hs_ready
,
()
=>
message
.
ctos_hs_ready
=
CtosHsReady
.
deserialize
(
reader
));
break
;
default
:
reader
.
skipField
();
}
}
...
...
@@ -614,6 +648,46 @@ export namespace ygopro {
return
CtosUpdateDeck
.
deserialize
(
bytes
);
}
}
export
class
CtosHsReady
extends
pb_1
.
Message
{
#
one_of_decls
:
number
[][]
=
[];
constructor
(
data
?:
any
[]
|
{})
{
super
();
pb_1
.
Message
.
initialize
(
this
,
Array
.
isArray
(
data
)
?
data
:
[],
0
,
-
1
,
[],
this
.
#
one_of_decls
);
if
(
!
Array
.
isArray
(
data
)
&&
typeof
data
==
"
object
"
)
{
}
}
static
fromObject
(
data
:
{}):
CtosHsReady
{
const
message
=
new
CtosHsReady
({});
return
message
;
}
toObject
()
{
const
data
:
{}
=
{};
return
data
;
}
serialize
():
Uint8Array
;
serialize
(
w
:
pb_1
.
BinaryWriter
):
void
;
serialize
(
w
?:
pb_1
.
BinaryWriter
):
Uint8Array
|
void
{
const
writer
=
w
||
new
pb_1
.
BinaryWriter
();
if
(
!
w
)
return
writer
.
getResultBuffer
();
}
static
deserialize
(
bytes
:
Uint8Array
|
pb_1
.
BinaryReader
):
CtosHsReady
{
const
reader
=
bytes
instanceof
pb_1
.
BinaryReader
?
bytes
:
new
pb_1
.
BinaryReader
(
bytes
),
message
=
new
CtosHsReady
();
while
(
reader
.
nextField
())
{
if
(
reader
.
isEndGroup
())
break
;
switch
(
reader
.
getFieldNumber
())
{
default
:
reader
.
skipField
();
}
}
return
message
;
}
serializeBinary
():
Uint8Array
{
return
this
.
serialize
();
}
static
deserializeBinary
(
bytes
:
Uint8Array
):
CtosHsReady
{
return
CtosHsReady
.
deserialize
(
bytes
);
}
}
export
class
StocJoinGame
extends
pb_1
.
Message
{
#
one_of_decls
:
number
[][]
=
[];
constructor
(
data
?:
any
[]
|
{
...
...
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