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
deft
Neos
Commits
6b87ae77
Commit
6b87ae77
authored
Dec 02, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update handSlice
parent
284661fb
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
72 deletions
+39
-72
src/api/cards.ts
src/api/cards.ts
+1
-1
src/reducers/duel/handsSlice.ts
src/reducers/duel/handsSlice.ts
+33
-56
src/reducers/duel/mod.ts
src/reducers/duel/mod.ts
+3
-4
src/service/duel/draw.ts
src/service/duel/draw.ts
+2
-11
No files found.
src/api/cards.ts
View file @
6b87ae77
import
axios
from
"
axios
"
;
import
axios
from
"
axios
"
;
interface
CardMeta
{
export
interface
CardMeta
{
id
:
number
;
id
:
number
;
data
:
{
data
:
{
ot
?:
number
;
ot
?:
number
;
...
...
src/reducers/duel/handsSlice.ts
View file @
6b87ae77
import
{
import
{
createAsyncThunk
,
ActionReducerMapBuilder
}
from
"
@reduxjs/toolkit
"
;
PayloadAction
,
CaseReducer
,
createAsyncThunk
,
ActionReducerMapBuilder
,
}
from
"
@reduxjs/toolkit
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
Card
,
fetchCard
}
from
"
../../api/cards
"
;
import
{
Card
,
fetchCard
,
CardMeta
}
from
"
../../api/cards
"
;
import
{
judgeSelf
}
from
"
./util
"
;
import
{
judgeSelf
}
from
"
./util
"
;
import
*
as
UICONFIG
from
"
../../config/ui
"
;
import
*
as
UICONFIG
from
"
../../config/ui
"
;
...
@@ -15,16 +10,33 @@ export interface Hands {
...
@@ -15,16 +10,33 @@ export interface Hands {
}
}
// 增加手牌
// 增加手牌
export
const
addHandsImpl
:
CaseReducer
<
export
const
fetchHandsMeta
=
createAsyncThunk
(
DuelState
,
"
duel/fetchHandsMeta
"
,
PayloadAction
<
[
number
,
number
[]]
>
async
(
param
:
[
number
,
number
[]])
=>
{
>
=
(
state
,
action
)
=>
{
const
player
=
param
[
0
];
const
Ids
=
param
[
1
];
const
metas
=
await
Promise
.
all
(
Ids
.
filter
((
id
)
=>
{
return
id
!==
0
;
}).
map
(
async
(
id
)
=>
{
return
await
fetchCard
(
id
);
})
);
const
response
:
[
number
,
CardMeta
[]]
=
[
player
,
metas
];
return
response
;
}
);
export
const
handsCase
=
(
builder
:
ActionReducerMapBuilder
<
DuelState
>
)
=>
{
builder
.
addCase
(
fetchHandsMeta
.
fulfilled
,
(
state
,
action
)
=>
{
const
player
=
action
.
payload
[
0
];
const
player
=
action
.
payload
[
0
];
const
hands
=
action
.
payload
[
1
];
const
hands
=
action
.
payload
[
1
];
const
selfType
=
state
.
selfType
;
const
selfType
=
state
.
selfType
;
const
cards
=
hands
.
map
((
id
)
=>
{
const
cards
=
hands
.
map
((
meta
)
=>
{
return
{
meta
:
{
id
,
data
:
{},
text
:
{}
}
,
transform
:
{}
};
return
{
meta
,
transform
:
{}
};
});
});
if
(
judgeSelf
(
player
,
selfType
))
{
if
(
judgeSelf
(
player
,
selfType
))
{
if
(
state
.
meHands
)
{
if
(
state
.
meHands
)
{
...
@@ -40,41 +52,6 @@ export const addHandsImpl: CaseReducer<
...
@@ -40,41 +52,6 @@ export const addHandsImpl: CaseReducer<
state
.
opHands
=
{
cards
};
state
.
opHands
=
{
cards
};
}
}
}
}
};
export
const
fetchMeHandsMeta
=
createAsyncThunk
(
"
duel/fetchMeHandsMeta
"
,
async
(
Ids
:
number
[])
=>
{
return
await
Promise
.
all
(
Ids
.
map
(
async
(
id
)
=>
{
return
await
fetchCard
(
id
);
})
);
}
);
export
const
meHandsCase
=
(
builder
:
ActionReducerMapBuilder
<
DuelState
>
)
=>
{
builder
.
addCase
(
fetchMeHandsMeta
.
fulfilled
,
(
state
,
action
)
=>
{
// TODO: 合法性校验
const
cardMetas
=
action
.
payload
;
if
(
state
.
meHands
)
{
for
(
let
meta
of
cardMetas
)
{
for
(
let
hand
of
state
.
meHands
.
cards
)
{
if
(
hand
.
meta
.
id
===
meta
.
id
)
{
hand
.
meta
=
meta
;
}
}
}
}
else
{
state
.
meHands
=
{
cards
:
cardMetas
.
map
((
meta
)
=>
{
return
{
meta
,
transform
:
{}
};
}),
};
setHandsTransform
(
state
.
meHands
.
cards
);
}
});
});
};
};
...
...
src/reducers/duel/mod.ts
View file @
6b87ae77
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
import
{
createSlice
,
PayloadAction
}
from
"
@reduxjs/toolkit
"
;
import
{
createSlice
,
PayloadAction
}
from
"
@reduxjs/toolkit
"
;
import
{
InitInfo
,
infoInitImpl
}
from
"
./initInfoSlice
"
;
import
{
InitInfo
,
infoInitImpl
}
from
"
./initInfoSlice
"
;
import
{
Hands
,
addHandsImpl
,
meH
andsCase
}
from
"
./handsSlice
"
;
import
{
Hands
,
h
andsCase
}
from
"
./handsSlice
"
;
import
{
newTurnImpl
}
from
"
./turnSlice
"
;
import
{
newTurnImpl
}
from
"
./turnSlice
"
;
import
{
newPhaseImpl
}
from
"
./phaseSlice
"
;
import
{
newPhaseImpl
}
from
"
./phaseSlice
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
RootState
}
from
"
../../store
"
;
...
@@ -30,16 +30,15 @@ const duelSlice = createSlice({
...
@@ -30,16 +30,15 @@ const duelSlice = createSlice({
state
.
selfType
=
action
.
payload
;
state
.
selfType
=
action
.
payload
;
},
},
infoInit
:
infoInitImpl
,
infoInit
:
infoInitImpl
,
addHands
:
addHandsImpl
,
updateTurn
:
newTurnImpl
,
updateTurn
:
newTurnImpl
,
updatePhase
:
newPhaseImpl
,
updatePhase
:
newPhaseImpl
,
},
},
extraReducers
(
builder
)
{
extraReducers
(
builder
)
{
meH
andsCase
(
builder
);
h
andsCase
(
builder
);
},
},
});
});
export
const
{
setSelfType
,
infoInit
,
addHands
,
updateTurn
,
updatePhase
}
=
export
const
{
setSelfType
,
infoInit
,
updateTurn
,
updatePhase
}
=
duelSlice
.
actions
;
duelSlice
.
actions
;
export
const
selectDuelHsStart
=
(
state
:
RootState
)
=>
{
export
const
selectDuelHsStart
=
(
state
:
RootState
)
=>
{
return
state
.
duel
.
meInitInfo
!=
null
;
return
state
.
duel
.
meInitInfo
!=
null
;
...
...
src/service/duel/draw.ts
View file @
6b87ae77
import
{
ygopro
}
from
"
../../api/ocgcore/idl/ocgcore
"
;
import
{
ygopro
}
from
"
../../api/ocgcore/idl/ocgcore
"
;
import
{
AppDispatch
}
from
"
../../store
"
;
import
{
AppDispatch
}
from
"
../../store
"
;
import
{
addHands
}
from
"
../../reducers/duel/mod
"
;
import
{
fetchHandsMeta
}
from
"
../../reducers/duel/handsSlice
"
;
import
{
fetchMeHandsMeta
}
from
"
../../reducers/duel/handsSlice
"
;
export
default
(
export
default
(
draw
:
ygopro
.
StocGameMessage
.
MsgDraw
,
draw
:
ygopro
.
StocGameMessage
.
MsgDraw
,
dispatch
:
AppDispatch
dispatch
:
AppDispatch
)
=>
{
)
=>
{
// FIXME: draw.player 和先后攻有关系
dispatch
(
fetchHandsMeta
([
draw
.
player
,
draw
.
cards
]));
if
(
draw
.
player
===
0
)
{
dispatch
(
addHands
([
0
,
draw
.
cards
]));
dispatch
(
fetchMeHandsMeta
(
draw
.
cards
));
}
else
if
(
draw
.
player
===
1
)
{
dispatch
(
addHands
([
1
,
draw
.
cards
]));
}
else
{
console
.
log
(
"
Currently only support 2v2 mode.
"
);
}
};
};
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