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
5d36736c
Commit
5d36736c
authored
Jul 14, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add replayStore.ts
parent
f6f681cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
src/stores/index.ts
src/stores/index.ts
+3
-0
src/stores/replayStore.ts
src/stores/replayStore.ts
+51
-0
No files found.
src/stores/index.ts
View file @
5d36736c
...
...
@@ -5,6 +5,7 @@ export * from "./matStore";
export
*
from
"
./moraStore
"
;
export
*
from
"
./placeStore
"
;
export
*
from
"
./playerStore
"
;
export
*
from
"
./replayStore
"
;
import
{
devtools
}
from
"
valtio/utils
"
;
...
...
@@ -15,6 +16,7 @@ import { matStore } from "./matStore";
import
{
moraStore
}
from
"
./moraStore
"
;
import
{
placeStore
}
from
"
./placeStore
"
;
import
{
playerStore
}
from
"
./playerStore
"
;
import
{
replayStore
}
from
"
./replayStore
"
;
devtools
(
playerStore
,
{
name
:
"
player
"
,
enabled
:
true
});
devtools
(
chatStore
,
{
name
:
"
chat
"
,
enabled
:
true
});
...
...
@@ -23,3 +25,4 @@ devtools(moraStore, { name: "mora", enabled: true });
devtools
(
matStore
,
{
name
:
"
mat
"
,
enabled
:
true
});
devtools
(
cardStore
,
{
name
:
"
card
"
,
enabled
:
true
});
devtools
(
placeStore
,
{
name
:
"
place
"
,
enabled
:
true
});
devtools
(
replayStore
,
{
name
:
"
replay
"
,
enabled
:
true
});
src/stores/replayStore.ts
0 → 100644
View file @
5d36736c
import
{
proxy
}
from
"
valtio
"
;
import
{
YgoProPacket
}
from
"
@/api/ocgcore/ocgAdapter/packet
"
;
// 对局中每一次状态改变的记录
interface
ReplaySpot
{
msg
:
string
;
// 人类能理解的语音,后续考虑用来在对局中展示
packet
:
ReplayPacket
;
// 将会保存在回放文件中的数据
}
// 保存回放信息的数据包
interface
ReplayPacket
{
func
:
number
;
// 对应的`GAME_MSG`编号
extraData
:
ArrayBuffer
;
}
class
ReplayStore
{
inner
:
ReplaySpot
[]
=
[];
record
(
ygoPacket
:
YgoProPacket
,
msg
?:
string
)
{
this
.
inner
.
push
({
msg
:
msg
??
""
,
packet
:
ygoPacket2replayPacket
(
ygoPacket
),
});
}
encode
():
ArrayBuffer
[]
{
return
this
.
inner
.
map
((
spot
)
=>
spot
.
packet
).
map
(
replayPacket2arrayBuffer
);
}
clear
()
{
this
.
inner
=
[];
}
}
const
ygoPacket2replayPacket
=
(
ygoPacket
:
YgoProPacket
)
=>
({
func
:
ygoPacket
.
exData
[
0
],
extraData
:
ygoPacket
.
exData
.
slice
(
1
),
});
const
replayPacket2arrayBuffer
=
(
replayPacket
:
ReplayPacket
)
=>
{
const
{
func
,
extraData
}
=
replayPacket
;
const
packetLen
=
1
+
4
+
extraData
.
byteLength
;
const
array
=
new
Uint8Array
(
packetLen
);
const
dataview
=
new
DataView
(
array
.
buffer
);
dataview
.
setUint8
(
0
,
func
);
dataview
.
setUint32
(
1
,
extraData
.
byteLength
,
true
);
array
.
set
(
new
Uint8Array
(
extraData
),
5
);
return
array
.
buffer
;
};
export
const
replayStore
=
proxy
(
new
ReplayStore
());
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