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
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
Hide 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
"
;
interface
CardMeta
{
export
interface
CardMeta
{
id
:
number
;
data
:
{
ot
?:
number
;
...
...
src/reducers/duel/handsSlice.ts
View file @
6b87ae77
import
{
PayloadAction
,
CaseReducer
,
createAsyncThunk
,
ActionReducerMapBuilder
,
}
from
"
@reduxjs/toolkit
"
;
import
{
createAsyncThunk
,
ActionReducerMapBuilder
}
from
"
@reduxjs/toolkit
"
;
import
{
DuelState
}
from
"
./mod
"
;
import
{
RootState
}
from
"
../../store
"
;
import
{
Card
,
fetchCard
}
from
"
../../api/cards
"
;
import
{
Card
,
fetchCard
,
CardMeta
}
from
"
../../api/cards
"
;
import
{
judgeSelf
}
from
"
./util
"
;
import
*
as
UICONFIG
from
"
../../config/ui
"
;
...
...
@@ -15,65 +10,47 @@ export interface Hands {
}
// 增加手牌
export
const
addHandsImpl
:
CaseReducer
<
DuelState
,
PayloadAction
<
[
number
,
number
[]]
>
>
=
(
state
,
action
)
=>
{
const
player
=
action
.
payload
[
0
];
const
hands
=
action
.
payload
[
1
];
const
selfType
=
state
.
selfType
;
export
const
fetchHandsMeta
=
createAsyncThunk
(
"
duel/fetchHandsMeta
"
,
async
(
param
:
[
number
,
number
[]])
=>
{
const
player
=
param
[
0
];
const
Ids
=
param
[
1
];
const
cards
=
hands
.
map
((
id
)
=>
{
return
{
meta
:
{
id
,
data
:
{},
text
:
{}
},
transform
:
{}
};
});
if
(
judgeSelf
(
player
,
selfType
))
{
if
(
state
.
meHands
)
{
state
.
meHands
.
cards
=
state
.
meHands
.
cards
.
concat
(
cards
);
}
else
{
state
.
meHands
=
{
cards
};
}
setHandsTransform
(
state
.
meHands
.
cards
);
}
else
{
if
(
state
.
opHands
)
{
state
.
opHands
.
cards
=
state
.
opHands
.
cards
.
concat
(
cards
);
}
else
{
state
.
opHands
=
{
cards
};
}
}
};
export
const
fetchMeHandsMeta
=
createAsyncThunk
(
"
duel/fetchMeHandsMeta
"
,
async
(
Ids
:
number
[])
=>
{
return
await
Promise
.
all
(
Ids
.
map
(
async
(
id
)
=>
{
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
meHandsCase
=
(
builder
:
ActionReducerMapBuilder
<
DuelState
>
)
=>
{
builder
.
addCase
(
fetchMeHandsMeta
.
fulfilled
,
(
state
,
action
)
=>
{
// TODO: 合法性校验
const
cardMetas
=
action
.
payload
;
export
const
handsCase
=
(
builder
:
ActionReducerMapBuilder
<
DuelState
>
)
=>
{
builder
.
addCase
(
fetchHandsMeta
.
fulfilled
,
(
state
,
action
)
=>
{
const
player
=
action
.
payload
[
0
];
const
hands
=
action
.
payload
[
1
];
const
selfType
=
state
.
selfType
;
if
(
state
.
meHands
)
{
for
(
let
meta
of
cardMetas
)
{
for
(
let
hand
of
state
.
meHands
.
cards
)
{
if
(
hand
.
meta
.
id
===
meta
.
id
)
{
hand
.
meta
=
meta
;
}
}
const
cards
=
hands
.
map
((
meta
)
=>
{
return
{
meta
,
transform
:
{}
};
});
if
(
judgeSelf
(
player
,
selfType
))
{
if
(
state
.
meHands
)
{
state
.
meHands
.
cards
=
state
.
meHands
.
cards
.
concat
(
cards
);
}
else
{
state
.
meHands
=
{
cards
};
}
}
else
{
state
.
meHands
=
{
cards
:
cardMetas
.
map
((
meta
)
=>
{
return
{
meta
,
transform
:
{}
};
}),
};
setHandsTransform
(
state
.
meHands
.
cards
);
}
else
{
if
(
state
.
opHands
)
{
state
.
opHands
.
cards
=
state
.
opHands
.
cards
.
concat
(
cards
);
}
else
{
state
.
opHands
=
{
cards
};
}
}
});
};
...
...
src/reducers/duel/mod.ts
View file @
6b87ae77
...
...
@@ -5,7 +5,7 @@
import
{
createSlice
,
PayloadAction
}
from
"
@reduxjs/toolkit
"
;
import
{
InitInfo
,
infoInitImpl
}
from
"
./initInfoSlice
"
;
import
{
Hands
,
addHandsImpl
,
meH
andsCase
}
from
"
./handsSlice
"
;
import
{
Hands
,
h
andsCase
}
from
"
./handsSlice
"
;
import
{
newTurnImpl
}
from
"
./turnSlice
"
;
import
{
newPhaseImpl
}
from
"
./phaseSlice
"
;
import
{
RootState
}
from
"
../../store
"
;
...
...
@@ -30,16 +30,15 @@ const duelSlice = createSlice({
state
.
selfType
=
action
.
payload
;
},
infoInit
:
infoInitImpl
,
addHands
:
addHandsImpl
,
updateTurn
:
newTurnImpl
,
updatePhase
:
newPhaseImpl
,
},
extraReducers
(
builder
)
{
meH
andsCase
(
builder
);
h
andsCase
(
builder
);
},
});
export
const
{
setSelfType
,
infoInit
,
addHands
,
updateTurn
,
updatePhase
}
=
export
const
{
setSelfType
,
infoInit
,
updateTurn
,
updatePhase
}
=
duelSlice
.
actions
;
export
const
selectDuelHsStart
=
(
state
:
RootState
)
=>
{
return
state
.
duel
.
meInitInfo
!=
null
;
...
...
src/service/duel/draw.ts
View file @
6b87ae77
import
{
ygopro
}
from
"
../../api/ocgcore/idl/ocgcore
"
;
import
{
AppDispatch
}
from
"
../../store
"
;
import
{
addHands
}
from
"
../../reducers/duel/mod
"
;
import
{
fetchMeHandsMeta
}
from
"
../../reducers/duel/handsSlice
"
;
import
{
fetchHandsMeta
}
from
"
../../reducers/duel/handsSlice
"
;
export
default
(
draw
:
ygopro
.
StocGameMessage
.
MsgDraw
,
dispatch
:
AppDispatch
)
=>
{
// FIXME: draw.player 和先后攻有关系
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.
"
);
}
dispatch
(
fetchHandsMeta
([
draw
.
player
,
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