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
2c415f42
Commit
2c415f42
authored
Apr 20, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: valtio store logic 40%
parent
ef0484d8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
18 deletions
+80
-18
src/service/duel/selectPlace.ts
src/service/duel/selectPlace.ts
+14
-2
src/service/duel/selectPosition.ts
src/service/duel/selectPosition.ts
+5
-1
src/service/duel/start.ts
src/service/duel/start.ts
+14
-4
src/valtioStores/matStore/index.ts
src/valtioStores/matStore/index.ts
+19
-6
src/valtioStores/matStore/types.ts
src/valtioStores/matStore/types.ts
+28
-5
No files found.
src/service/duel/selectPlace.ts
View file @
2c415f42
...
...
@@ -6,6 +6,10 @@ import {
addMonsterPlaceInteractivities
,
}
from
"
@/reducers/duel/mod
"
;
import
{
InteractType
,
valtioStore
}
from
"
@/valtioStores
"
;
const
{
matStore
}
=
valtioStore
;
export
default
(
selectPlace
:
MsgSelectPlace
,
dispatch
:
AppDispatch
)
=>
{
if
(
selectPlace
.
count
!=
1
)
{
console
.
warn
(
`Unhandled case:
${
selectPlace
}
`
);
...
...
@@ -19,14 +23,22 @@ export default (selectPlace: MsgSelectPlace, dispatch: AppDispatch) => {
dispatch
(
addMonsterPlaceInteractivities
([
place
.
controler
,
place
.
sequence
])
);
matStore
.
monsters
.
setPlaceInteractivityType
(
place
.
controler
,
place
.
sequence
,
InteractType
.
PLACE_SELECTABLE
);
break
;
}
case
ygopro
.
CardZone
.
SZONE
:
{
dispatch
(
addMagicPlaceInteractivities
([
place
.
controler
,
place
.
sequence
])
);
matStore
.
magics
.
setPlaceInteractivityType
(
place
.
controler
,
place
.
sequence
,
InteractType
.
PLACE_SELECTABLE
);
break
;
}
default
:
{
...
...
src/service/duel/selectPosition.ts
View file @
2c415f42
...
...
@@ -4,7 +4,10 @@ import {
setPositionModalPositions
,
}
from
"
@/reducers/duel/mod
"
;
import
{
AppDispatch
}
from
"
@/store
"
;
import
MsgSelectPosition
=
ygopro
.
StocGameMessage
.
MsgSelectPosition
;
import
{
matStore
}
from
"
@/valtioStores
"
;
type
MsgSelectPosition
=
ygopro
.
StocGameMessage
.
MsgSelectPosition
;
export
default
(
selectPosition
:
MsgSelectPosition
,
dispatch
:
AppDispatch
)
=>
{
const
player
=
selectPosition
.
player
;
...
...
@@ -13,5 +16,6 @@ export default (selectPosition: MsgSelectPosition, dispatch: AppDispatch) => {
dispatch
(
setPositionModalPositions
(
positions
.
map
((
position
)
=>
position
.
position
))
);
dispatch
(
setPositionModalIsOpen
(
true
));
};
src/service/duel/start.ts
View file @
2c415f42
...
...
@@ -53,6 +53,8 @@ export default (
},
])
);
// >>> 删除 >>>
dispatch
(
initMonsters
(
0
));
dispatch
(
initMonsters
(
1
));
dispatch
(
initMagics
(
0
));
...
...
@@ -63,10 +65,18 @@ export default (
dispatch
(
initDeck
({
player
:
0
,
deskSize
:
start
.
deckSize1
}));
dispatch
(
initDeck
({
player
:
1
,
deskSize
:
start
.
deckSize2
}));
matStore
.
decks
.
add
(
0
,
Array
(
start
.
deckSize1
).
fill
(
0
));
matStore
.
decks
.
add
(
1
,
Array
(
start
.
deckSize2
).
fill
(
0
));
dispatch
(
initBanishedZone
(
0
));
dispatch
(
initBanishedZone
(
1
));
dispatch
(
initHint
());
// <<< 删除 <<<
// 上面的删除就可以了
matStore
.
monsters
.
at
(
0
).
forEach
((
x
)
=>
(
x
.
location
.
controler
=
0
));
matStore
.
monsters
.
at
(
1
).
forEach
((
x
)
=>
(
x
.
location
.
controler
=
1
));
matStore
.
magics
.
at
(
0
).
forEach
((
x
)
=>
(
x
.
location
.
controler
=
0
));
matStore
.
magics
.
at
(
1
).
forEach
((
x
)
=>
(
x
.
location
.
controler
=
1
));
matStore
.
decks
.
add
(
0
,
Array
(
start
.
deckSize1
).
fill
(
0
));
matStore
.
decks
.
add
(
1
,
Array
(
start
.
deckSize2
).
fill
(
0
));
dispatch
(
initHint
());
// 直接删除
};
src/valtioStores/matStore/index.ts
View file @
2c415f42
export
*
from
"
./types
"
;
import
{
proxy
}
from
"
valtio
"
;
import
{
fetchCard
}
from
"
@/api/cards
"
;
...
...
@@ -11,6 +13,7 @@ import type {
InitInfo
,
PlayMatState
,
}
from
"
./types
"
;
import
{
InteractType
}
from
"
./types
"
;
import
{
DESCRIPTION_LIMIT
,
fetchStrings
,
getStrings
}
from
"
@/api/strings
"
;
/**
...
...
@@ -129,6 +132,9 @@ const wrap = <T extends DuelFieldState>(
const
res
:
CardsBothSide
<
T
>
=
proxy
({
...
entity
,
at
:
(
controller
:
number
)
=>
{
return
res
[
getWhom
(
controller
)];
},
remove
:
(
controller
:
number
,
sequence
:
number
)
=>
{
res
[
getWhom
(
controller
)].
splice
(
sequence
,
1
);
},
...
...
@@ -174,12 +180,19 @@ const wrap = <T extends DuelFieldState>(
clearIdleInteractivities
:
(
controller
:
number
,
sequence
:
number
)
=>
{
res
[
getWhom
(
controller
)][
sequence
].
idleInteractivities
=
[];
},
setPlaceInteractivity
:
(
setPlaceInteractivity
Type
:
(
controller
:
number
,
sequence
:
number
,
interact
ivity
:
CardState
[
"
placeInteractivity
"
]
interact
Type
:
InteractType
)
=>
{
res
[
getWhom
(
controller
)][
sequence
].
placeInteractivity
=
interactivity
;
res
[
getWhom
(
controller
)][
sequence
].
placeInteractivity
=
{
interactType
:
interactType
,
response
:
{
controler
:
controller
,
zone
,
sequence
,
},
};
},
clearPlaceInteractivity
:
(
controller
:
number
,
sequence
:
number
)
=>
{
res
[
getWhom
(
controller
)][
sequence
].
placeInteractivity
=
undefined
;
...
...
@@ -227,10 +240,10 @@ export const matStore = proxy<PlayMatState>({
* 根据controller判断是自己还是对方
* 不要往外export,尽量逻辑收拢在store内部
*/
const
getWhom
=
(
controller
:
number
)
=>
const
getWhom
=
(
controller
:
number
)
:
"
me
"
|
"
op
"
=>
judgeSelf
(
controller
,
matStore
.
selfType
)
?
"
me
"
:
"
op
"
;
function
judgeSelf
(
player
:
number
,
selfType
:
number
):
boolean
{
const
judgeSelf
=
(
player
:
number
,
selfType
:
number
):
boolean
=>
{
switch
(
selfType
)
{
case
1
:
// 自己是先攻
...
...
@@ -243,4 +256,4 @@ function judgeSelf(player: number, selfType: number): boolean {
console
.
error
(
"
judgeSelf error
"
,
player
,
selfType
);
return
false
;
}
}
}
;
src/valtioStores/matStore/types.ts
View file @
2c415f42
...
...
@@ -9,16 +9,39 @@ export interface BothSide<T> {
}
export
interface
CardsBothSide
<
T
extends
DuelFieldState
>
extends
BothSide
<
T
>
{
remove
:
(
player
:
number
,
sequence
:
number
)
=>
void
;
// 移除特定位置的卡片
add
:
(
controller
:
number
,
ids
:
number
[])
=>
void
;
// 在末尾添加卡片
insert
:
(
controller
:
number
,
sequence
:
number
,
id
:
number
)
=>
void
;
// 在指定位置插入卡片
/** 根据controller返回对应的数组 */
at
:
(
controller
:
number
)
=>
T
;
/** 移除特定位置的卡片 */
remove
:
(
player
:
number
,
sequence
:
number
)
=>
void
;
/** 在末尾添加卡片 */
add
:
(
controller
:
number
,
ids
:
number
[])
=>
void
;
/** 在指定位置插入卡片 */
insert
:
(
controller
:
number
,
sequence
:
number
,
id
:
number
)
=>
void
;
/** 设置占据这个位置的卡片信息 */
setOccupant
:
(
controller
:
number
,
sequence
:
number
,
id
:
number
,
position
?:
ygopro
.
CardPosition
)
=>
void
;
// 设置卡片的卡片信息
removeOccupant
:
(
controller
:
number
,
sequence
:
number
)
=>
void
;
// 移除卡片的卡片信息
)
=>
void
;
/** 移除卡片的卡片信息 */
removeOccupant
:
(
controller
:
number
,
sequence
:
number
)
=>
void
;
/** 添加 idle 的交互性 */
addIdleInteractivity
:
(
controller
:
number
,
sequence
:
number
,
interactivity
:
CardState
[
"
idleInteractivities
"
][
number
]
)
=>
void
;
/** 移除 idle 的交互性 */
clearIdleInteractivities
:
(
controller
:
number
,
sequence
:
number
)
=>
void
;
/** 设置 place 的交互种类 */
setPlaceInteractivityType
:
(
controller
:
number
,
sequence
:
number
,
interactType
:
InteractType
)
=>
void
;
/** 移除 place 的交互性 */
clearPlaceInteractivity
:
(
controller
:
number
,
sequence
:
number
)
=>
void
;
}
export
interface
PlayMatState
{
...
...
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