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
96426b81
Commit
96426b81
authored
Jul 15, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update stores
parent
479b7694
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
86 additions
and
24 deletions
+86
-24
src/stores/cardStore.ts
src/stores/cardStore.ts
+5
-1
src/stores/chatStore.ts
src/stores/chatStore.ts
+6
-1
src/stores/joinStore.ts
src/stores/joinStore.ts
+6
-1
src/stores/matStore/store.ts
src/stores/matStore/store.ts
+16
-5
src/stores/matStore/types.ts
src/stores/matStore/types.ts
+3
-1
src/stores/placeStore.ts
src/stores/placeStore.ts
+28
-11
src/stores/playerStore.ts
src/stores/playerStore.ts
+13
-2
src/stores/replayStore.ts
src/stores/replayStore.ts
+4
-2
src/stores/shared.ts
src/stores/shared.ts
+5
-0
No files found.
src/stores/cardStore.ts
View file @
96426b81
...
...
@@ -3,6 +3,7 @@ import { proxy } from "valtio";
import
{
CardMeta
,
ygopro
}
from
"
@/api
"
;
import
type
{
Interactivity
}
from
"
./matStore/types
"
;
import
{
NeosStore
}
from
"
./shared
"
;
/**
* 场上某位置的状态
...
...
@@ -26,7 +27,7 @@ export interface CardType {
selected
:
boolean
;
// 当前卡是否被选择成为效果的对象
}
class
CardStore
{
class
CardStore
implements
NeosStore
{
inner
:
CardType
[]
=
[];
at
(
zone
:
ygopro
.
CardZone
,
controller
:
number
):
CardType
[];
at
(
...
...
@@ -90,6 +91,9 @@ class CardStore {
card
.
location
.
is_overlay
);
}
reset
():
void
{
this
.
inner
=
[];
}
}
export
const
cardStore
=
proxy
(
new
CardStore
());
...
...
src/stores/chatStore.ts
View file @
96426b81
import
{
proxy
}
from
"
valtio
"
;
export
interface
ChatState
{
import
{
NeosStore
}
from
"
./shared
"
;
export
interface
ChatState
extends
NeosStore
{
message
:
string
;
}
export
const
chatStore
=
proxy
<
ChatState
>
({
message
:
""
,
reset
()
{
chatStore
.
message
=
""
;
},
});
src/stores/joinStore.ts
View file @
96426b81
import
{
proxy
}
from
"
valtio
"
;
export
interface
JoinState
{
import
{
NeosStore
}
from
"
./shared
"
;
export
interface
JoinState
extends
NeosStore
{
value
:
boolean
;
}
export
const
joinStore
=
proxy
<
JoinState
>
({
value
:
false
,
reset
()
{
joinStore
.
value
=
false
;
},
});
src/stores/matStore/store.ts
View file @
96426b81
/* eslint valtio/avoid-this-in-proxy: 0 */
import
{
Omit
}
from
"
@react-spring/web
"
;
import
{
proxy
}
from
"
valtio
"
;
import
{
ygopro
}
from
"
@/api
"
;
...
...
@@ -52,11 +53,7 @@ const initInfo: MatState["initInfo"] = (() => {
});
})();
/**
* 💡 决斗盘状态仓库,本文件核心,
* 具体介绍可以点进`MatState`去看
*/
export
const
matStore
:
MatState
=
proxy
<
MatState
>
({
const
initialState
:
Omit
<
MatState
,
"
reset
"
>
=
{
chains
:
[],
timeLimits
:
{
...
...
@@ -92,6 +89,20 @@ export const matStore: MatState = proxy<MatState>({
},
// methods
isMe
,
};
/**
* 💡 决斗盘状态仓库,本文件核心,
* 具体介绍可以点进`MatState`去看
*/
export
const
matStore
:
MatState
=
proxy
<
MatState
>
({
...
initialState
,
reset
()
{
Object
.
entries
(
initialState
).
forEach
((
key
)
=>
{
// @ts-ignore
matStore
[
key
]
=
initialState
[
key
];
});
},
});
// @ts-ignore 挂到全局,便于调试
...
...
src/stores/matStore/types.ts
View file @
96426b81
import
type
{
ygopro
}
from
"
@/api
"
;
import
{
NeosStore
}
from
"
../shared
"
;
// >>> play mat state >>>
export
interface
BothSide
<
T
>
{
...
...
@@ -9,7 +11,7 @@ export interface BothSide<T> {
of
:
(
controller
:
number
)
=>
T
;
}
export
interface
MatState
{
export
interface
MatState
extends
NeosStore
{
selfType
:
number
;
initInfo
:
BothSide
<
InitInfo
>
&
{
...
...
src/stores/placeStore.ts
View file @
96426b81
...
...
@@ -4,6 +4,7 @@ import { ygopro } from "@/api";
import
{
matStore
}
from
"
@/stores
"
;
import
type
{
Interactivity
}
from
"
./matStore/types
"
;
import
{
NeosStore
}
from
"
./shared
"
;
export
type
PlaceInteractivity
=
|
Interactivity
<
{
...
...
@@ -26,17 +27,28 @@ const genPLaces = (n: number): BlockState[] =>
disabled
:
false
,
}));
export
const
placeStore
=
proxy
({
const
initialState
=
{
[
MZONE
]:
{
me
:
genPLaces
(
7
),
op
:
genPLaces
(
7
),
},
[
SZONE
]:
{
me
:
genPLaces
(
6
),
op
:
genPLaces
(
6
),
},
};
class
PlaceStore
implements
NeosStore
{
inner
:
{
[
MZONE
]:
{
me
:
genPLaces
(
7
),
op
:
genPLaces
(
7
),
}
,
me
:
BlockState
[];
op
:
BlockState
[];
}
;
[
SZONE
]:
{
me
:
genPLaces
(
6
),
op
:
genPLaces
(
6
),
}
,
}
,
me
:
BlockState
[];
op
:
BlockState
[];
}
;
}
=
initialState
;
set
(
zone
:
ygopro
.
CardZone
.
MZONE
|
ygopro
.
CardZone
.
SZONE
,
controller
:
number
,
...
...
@@ -45,7 +57,7 @@ export const placeStore = proxy({
)
{
placeStore
.
inner
[
zone
][
matStore
.
isMe
(
controller
)
?
"
me
"
:
"
op
"
][
sequence
]
=
state
;
}
,
}
clearAllInteractivity
()
{
([
"
me
"
,
"
op
"
]
as
const
).
forEach
((
who
)
=>
{
([
MZONE
,
SZONE
]
as
const
).
forEach
((
where
)
=>
{
...
...
@@ -54,5 +66,10 @@ export const placeStore = proxy({
);
});
});
},
});
}
reset
():
void
{
placeStore
.
inner
=
initialState
;
}
}
export
const
placeStore
=
proxy
(
new
PlaceStore
());
src/stores/playerStore.ts
View file @
96426b81
...
...
@@ -3,6 +3,7 @@ import { proxy } from "valtio";
import
{
ygopro
}
from
"
@/api
"
;
import
SelfType
=
ygopro
.
StocTypeChange
.
SelfType
;
import
{
NeosStore
}
from
"
./shared
"
;
export
interface
Player
{
name
?:
string
;
...
...
@@ -17,7 +18,7 @@ export interface deckInfo {
sideCnt
:
number
;
}
export
interface
PlayerState
{
export
interface
PlayerState
extends
NeosStore
{
player0
:
Player
;
player1
:
Player
;
observerCount
:
number
;
...
...
@@ -27,12 +28,16 @@ export interface PlayerState {
getOpPlayer
:
()
=>
Player
;
}
export
const
playerStore
=
proxy
<
PlayerState
>
(
{
const
initialState
=
{
player0
:
{},
player1
:
{},
observerCount
:
0
,
isHost
:
false
,
selfType
:
SelfType
.
UNKNOWN
,
};
export
const
playerStore
=
proxy
<
PlayerState
>
({
...
initialState
,
getMePlayer
()
{
if
(
this
.
selfType
===
SelfType
.
PLAYER1
)
return
this
.
player0
;
return
this
.
player1
;
...
...
@@ -41,4 +46,10 @@ export const playerStore = proxy<PlayerState>({
if
(
this
.
selfType
===
SelfType
.
PLAYER1
)
return
this
.
player1
;
return
this
.
player0
;
},
reset
()
{
Object
.
entries
(
initialState
).
forEach
((
key
)
=>
{
// @ts-ignore
playerStore
[
key
]
=
initialState
[
key
];
});
},
});
src/stores/replayStore.ts
View file @
96426b81
...
...
@@ -2,6 +2,8 @@ import { proxy } from "valtio";
import
{
YgoProPacket
}
from
"
@/api/ocgcore/ocgAdapter/packet
"
;
import
{
NeosStore
}
from
"
./shared
"
;
// 对局中每一次状态改变的记录
interface
ReplaySpot
{
packet
:
ReplayPacket
;
// 将会保存在回放文件中的数据
...
...
@@ -14,7 +16,7 @@ interface ReplayPacket {
}
// 保存对局回放数据的`Store`
class
ReplayStore
{
class
ReplayStore
implements
NeosStore
{
inner
:
ReplaySpot
[]
=
[];
record
(
ygoPacket
:
YgoProPacket
)
{
this
.
inner
.
push
({
...
...
@@ -24,7 +26,7 @@ class ReplayStore {
encode
():
ArrayBuffer
[]
{
return
this
.
inner
.
map
((
spot
)
=>
spot
.
packet
).
map
(
replayPacket2arrayBuffer
);
}
clear
()
{
reset
()
{
this
.
inner
=
[];
}
}
...
...
src/stores/shared.ts
0 → 100644
View file @
96426b81
// Neos项目中所有Store需要实现的接口
// 用于统一管理状态的初始化和重置
export
interface
NeosStore
{
reset
():
void
;
}
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