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
51bd0e23
Commit
51bd0e23
authored
Nov 19, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add hands slice
parent
972ed5f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
9 deletions
+60
-9
src/reducers/duel/handsSlice.ts
src/reducers/duel/handsSlice.ts
+30
-0
src/reducers/duel/initInfoSlice.ts
src/reducers/duel/initInfoSlice.ts
+19
-0
src/reducers/duel/mod.ts
src/reducers/duel/mod.ts
+11
-9
No files found.
src/reducers/duel/handsSlice.ts
0 → 100644
View file @
51bd0e23
import
{
PayloadAction
,
CaseReducer
}
from
"
@reduxjs/toolkit
"
;
import
{
DuelState
}
from
"
./mod
"
;
export
interface
Hands
{
cards
:
number
[];
// TODO: use Card struct Unitly
}
// 自己增加手牌
export
const
meAddHandsImpl
:
CaseReducer
<
DuelState
,
PayloadAction
<
number
[]
>>
=
(
state
,
action
)
=>
{
if
(
state
.
meHands
)
{
state
.
meHands
.
cards
=
state
.
meHands
.
cards
.
concat
(
action
.
payload
);
}
else
{
state
.
meHands
=
{
cards
:
action
.
payload
};
}
};
// 对手增加手牌
export
const
opAddHandsImpl
:
CaseReducer
<
DuelState
,
PayloadAction
<
number
[]
>>
=
(
state
,
action
)
=>
{
if
(
state
.
opHands
)
{
state
.
opHands
.
cards
=
state
.
opHands
.
cards
.
concat
(
action
.
payload
);
}
else
{
state
.
opHands
=
{
cards
:
action
.
payload
};
}
};
src/reducers/duel/initInfoSlice.ts
View file @
51bd0e23
import
{
PayloadAction
,
CaseReducer
}
from
"
@reduxjs/toolkit
"
;
import
{
DuelState
}
from
"
./mod
"
;
export
interface
InitInfo
{
playerType
?:
string
;
masterRule
?:
string
;
...
...
@@ -5,3 +8,19 @@ export interface InitInfo {
deckSize
:
number
;
extraSize
:
number
;
}
// 更新自己的初始生命值,卡组信息
export
const
meInfoInitImpl
:
CaseReducer
<
DuelState
,
PayloadAction
<
InitInfo
>>
=
(
state
,
action
)
=>
{
state
.
meInitInfo
=
action
.
payload
;
};
// 更新对手的初始生命值,卡组信息
export
const
opInfoInitImpl
:
CaseReducer
<
DuelState
,
PayloadAction
<
InitInfo
>>
=
(
state
,
action
)
=>
{
state
.
opInitInfo
=
action
.
payload
;
};
src/reducers/duel/mod.ts
View file @
51bd0e23
...
...
@@ -3,12 +3,15 @@
*
* */
import
{
createSlice
,
PayloadAction
}
from
"
@reduxjs/toolkit
"
;
import
{
InitInfo
}
from
"
./initInfoSlice
"
;
import
{
createSlice
}
from
"
@reduxjs/toolkit
"
;
import
{
InitInfo
,
meInfoInitImpl
,
opInfoInitImpl
}
from
"
./initInfoSlice
"
;
import
{
Hands
,
meAddHandsImpl
,
opAddHandsImpl
}
from
"
./handsSlice
"
;
export
interface
DuelState
{
meInitInfo
?:
InitInfo
;
// 自己的初始状态
opInitInfo
?:
InitInfo
;
// 对手的初始状态
meHands
?:
Hands
;
// 自己的手牌
opHands
?:
Hands
;
// 对手的手牌
}
const
initialState
:
DuelState
=
{};
...
...
@@ -17,14 +20,13 @@ const duelSlice = createSlice({
name
:
"
duel
"
,
initialState
,
reducers
:
{
meInfoInit
:
(
state
,
action
:
PayloadAction
<
InitInfo
>
)
=>
{
state
.
meInitInfo
=
action
.
payload
;
},
opInfoInit
:
(
state
,
action
:
PayloadAction
<
InitInfo
>
)
=>
{
state
.
opInitInfo
=
action
.
payload
;
},
meInfoInit
:
meInfoInitImpl
,
opInfoInit
:
opInfoInitImpl
,
meAddHands
:
meAddHandsImpl
,
opAddHands
:
opAddHandsImpl
,
},
});
export
const
{
meInfoInit
,
opInfoInit
}
=
duelSlice
.
actions
;
export
const
{
meInfoInit
,
opInfoInit
,
meAddHands
,
opAddHands
}
=
duelSlice
.
actions
;
export
default
duelSlice
.
reducer
;
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