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
e28b64d3
Commit
e28b64d3
authored
Jan 15, 2023
by
chechunchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add createAsyncRepeatedMeta
parent
c082bb70
Pipeline
#19526
passed with stages
in 4 minutes and 26 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
26 deletions
+37
-26
src/reducers/duel/generic.ts
src/reducers/duel/generic.ts
+29
-0
src/reducers/duel/handsSlice.ts
src/reducers/duel/handsSlice.ts
+7
-25
src/service/duel/draw.ts
src/service/duel/draw.ts
+1
-1
No files found.
src/reducers/duel/generic.ts
View file @
e28b64d3
...
@@ -80,6 +80,35 @@ export function createAsyncMetaThunk(name: string): AsyncThunk<
...
@@ -80,6 +80,35 @@ export function createAsyncMetaThunk(name: string): AsyncThunk<
);
);
}
}
export
function
createAsyncRepeatedMetaThunk
(
name
:
string
):
AsyncThunk
<
{
controler
:
number
;
metas
:
CardMeta
[]
},
{
controler
:
number
;
codes
:
number
[]
},
{}
>
{
return
createAsyncThunk
(
name
,
async
(
param
:
{
controler
:
number
;
codes
:
number
[]
})
=>
{
const
controler
=
param
.
controler
;
const
Ids
=
param
.
codes
;
const
metas
=
await
Promise
.
all
(
Ids
.
map
(
async
(
id
)
=>
{
if
(
id
==
0
)
{
return
{
id
,
data
:
{},
text
:
{}
};
}
else
{
return
await
fetchCard
(
id
);
}
})
);
const
response
=
{
controler
,
metas
};
return
response
;
}
);
}
export
function
extendState
<
T
extends
DuelFieldState
>
(
export
function
extendState
<
T
extends
DuelFieldState
>
(
state
:
T
|
undefined
,
state
:
T
|
undefined
,
newState
:
CardState
newState
:
CardState
...
...
src/reducers/duel/handsSlice.ts
View file @
e28b64d3
import
{
import
{
createAsyncThunk
,
ActionReducerMapBuilder
,
ActionReducerMapBuilder
,
CaseReducer
,
CaseReducer
,
PayloadAction
,
PayloadAction
,
}
from
"
@reduxjs/toolkit
"
;
}
from
"
@reduxjs/toolkit
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
fetchCard
,
CardMeta
}
from
"
../../api/cards
"
;
import
{
judgeSelf
}
from
"
./util
"
;
import
{
judgeSelf
}
from
"
./util
"
;
import
{
import
{
Interactivity
,
Interactivity
,
...
@@ -15,31 +13,15 @@ import {
...
@@ -15,31 +13,15 @@ import {
createAsyncMetaThunk
,
createAsyncMetaThunk
,
insertCard
,
insertCard
,
extendMeta
,
extendMeta
,
createAsyncRepeatedMetaThunk
,
}
from
"
./generic
"
;
}
from
"
./generic
"
;
import
{
ygopro
}
from
"
../../api/ocgcore/idl/ocgcore
"
;
import
{
ygopro
}
from
"
../../api/ocgcore/idl/ocgcore
"
;
export
interface
HandState
extends
DuelFieldState
{}
export
interface
HandState
extends
DuelFieldState
{}
// 增加手牌
// 增加手牌
export
const
fetchHandsMeta
=
createAsyncThunk
(
export
const
fetchHandsMeta
=
createAsyncRepeatedMetaThunk
(
"
duel/fetchHandsMeta
"
,
"
duel/fetchHandsMeta
"
async
(
param
:
[
number
,
number
[]])
=>
{
const
player
=
param
[
0
];
const
Ids
=
param
[
1
];
const
metas
=
await
Promise
.
all
(
Ids
.
map
(
async
(
id
)
=>
{
if
(
id
===
0
)
{
return
{
id
,
data
:
{},
text
:
{}
};
}
else
{
return
await
fetchCard
(
id
);
}
})
);
const
response
:
[
number
,
CardMeta
[]]
=
[
player
,
metas
];
return
response
;
}
);
);
// 清空手牌互动性
// 清空手牌互动性
...
@@ -95,8 +77,8 @@ export const insertHandMeta = createAsyncMetaThunk("duel/insertHandMeta");
...
@@ -95,8 +77,8 @@ export const insertHandMeta = createAsyncMetaThunk("duel/insertHandMeta");
export
const
handsCase
=
(
builder
:
ActionReducerMapBuilder
<
DuelState
>
)
=>
{
export
const
handsCase
=
(
builder
:
ActionReducerMapBuilder
<
DuelState
>
)
=>
{
builder
.
addCase
(
fetchHandsMeta
.
pending
,
(
state
,
action
)
=>
{
builder
.
addCase
(
fetchHandsMeta
.
pending
,
(
state
,
action
)
=>
{
// Meta结果没返回之前先更新手牌`ID`
// Meta结果没返回之前先更新手牌`ID`
const
player
=
action
.
meta
.
arg
[
0
]
;
const
player
=
action
.
meta
.
arg
.
controler
;
const
ids
=
action
.
meta
.
arg
[
1
]
;
const
ids
=
action
.
meta
.
arg
.
codes
;
const
cards
=
ids
.
map
((
id
,
idx
)
=>
{
const
cards
=
ids
.
map
((
id
,
idx
)
=>
{
return
{
return
{
...
@@ -125,8 +107,8 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => {
...
@@ -125,8 +107,8 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => {
});
});
builder
.
addCase
(
fetchHandsMeta
.
fulfilled
,
(
state
,
action
)
=>
{
builder
.
addCase
(
fetchHandsMeta
.
fulfilled
,
(
state
,
action
)
=>
{
// `Meta`结果回来后更新手牌的`Meta`结果
// `Meta`结果回来后更新手牌的`Meta`结果
const
player
=
action
.
payload
[
0
]
;
const
player
=
action
.
payload
.
controler
;
const
metas
=
action
.
payload
[
1
]
;
const
metas
=
action
.
payload
.
metas
;
const
hands
=
judgeSelf
(
player
,
state
)
?
state
.
meHands
:
state
.
opHands
;
const
hands
=
judgeSelf
(
player
,
state
)
?
state
.
meHands
:
state
.
opHands
;
if
(
hands
)
{
if
(
hands
)
{
...
...
src/service/duel/draw.ts
View file @
e28b64d3
...
@@ -6,5 +6,5 @@ export default (
...
@@ -6,5 +6,5 @@ export default (
draw
:
ygopro
.
StocGameMessage
.
MsgDraw
,
draw
:
ygopro
.
StocGameMessage
.
MsgDraw
,
dispatch
:
AppDispatch
dispatch
:
AppDispatch
)
=>
{
)
=>
{
dispatch
(
fetchHandsMeta
(
[
draw
.
player
,
draw
.
cards
]
));
dispatch
(
fetchHandsMeta
(
{
controler
:
draw
.
player
,
codes
:
draw
.
cards
}
));
};
};
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