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
90dbb589
Commit
90dbb589
authored
Nov 20, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add cardsSlice
parent
ca5e9b02
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
2 deletions
+85
-2
src/api/cards.ts
src/api/cards.ts
+33
-0
src/api/deck.ts
src/api/deck.ts
+0
-0
src/api/ocgcore/ocgHelper.ts
src/api/ocgcore/ocgHelper.ts
+1
-1
src/reducers/cardsSlice.ts
src/reducers/cardsSlice.ts
+48
-0
src/store.ts
src/store.ts
+2
-0
src/ui/WaitRoom.tsx
src/ui/WaitRoom.tsx
+1
-1
No files found.
src/api/cards.ts
0 → 100644
View file @
90dbb589
import
axios
from
"
axios
"
;
export
interface
CardMeta
{
id
:
number
;
data
:
{
ot
?:
number
;
setcode
?:
number
;
type
?:
number
;
atk
?:
number
;
def
?:
number
;
level
?:
number
;
race
?:
number
;
attribute
?:
number
;
};
text
:
{
name
?:
string
;
types
?:
string
;
desc
?:
string
;
};
}
/*
* 返回卡片元数据
*
* @param id - 卡片id
* @returns 卡片数据
*
* */
export
async
function
fetchCard
(
id
:
number
):
Promise
<
CardMeta
>
{
const
res
=
await
axios
.
get
<
CardMeta
>
(
"
https://ygocdb.com/api/v0/card/
"
+
id
);
return
res
.
data
;
}
src/api/
Card
.ts
→
src/api/
deck
.ts
View file @
90dbb589
File moved
src/api/ocgcore/ocgHelper.ts
View file @
90dbb589
...
...
@@ -4,7 +4,7 @@
* */
import
{
ygopro
}
from
"
./idl/ocgcore
"
;
import
socketMiddleWare
,
{
socketCmd
}
from
"
../../middleware/socket
"
;
import
{
IDeck
}
from
"
../
Card
"
;
import
{
IDeck
}
from
"
../
deck
"
;
import
PlayerInfoAdapter
from
"
./ocgAdapter/ctos/ctosPlayerInfo
"
;
import
JoinGameAdapter
from
"
./ocgAdapter/ctos/ctosJoinGame
"
;
import
UpdateDeckAdapter
from
"
./ocgAdapter/ctos/ctosUpdateDeck
"
;
...
...
src/reducers/cardsSlice.ts
0 → 100644
View file @
90dbb589
/*
* 卡牌数据存储
*
* */
import
{
createSlice
,
createAsyncThunk
}
from
"
@reduxjs/toolkit
"
;
import
{
CardMeta
,
fetchCard
}
from
"
../api/cards
"
;
import
{
RootState
}
from
"
../store
"
;
export
const
fetchCardMetaById
=
createAsyncThunk
(
"
cards/fetchByIdStatus
"
,
async
(
cardId
:
number
)
=>
{
return
await
fetchCard
(
cardId
);
}
);
export
interface
Card
{
meta
?:
CardMeta
;
state
:
string
;
}
export
interface
CardMetaState
{
metas
:
Map
<
number
,
Card
>
;
}
const
initialState
:
CardMetaState
=
{
metas
:
new
Map
(),
};
const
cardsSlice
=
createSlice
({
name
:
"
cards
"
,
initialState
,
reducers
:
{},
extraReducers
:
(
builder
)
=>
{
builder
.
addCase
(
fetchCardMetaById
.
fulfilled
,
(
state
,
action
)
=>
{
const
id
=
action
.
payload
.
id
;
const
card
=
{
meta
:
action
.
payload
,
state
:
"
filled
"
,
};
state
.
metas
.
set
(
id
,
card
);
});
// TODO: handle pending and rejected
},
});
export
const
selectCard
=
(
state
:
RootState
,
id
:
number
)
=>
state
.
cards
.
metas
.
get
(
id
);
export
default
cardsSlice
.
reducer
;
src/store.ts
View file @
90dbb589
...
...
@@ -7,6 +7,7 @@ import chatReducer from "./reducers/chatSlice";
import
playerReducer
from
"
./reducers/playerSlice
"
;
import
moraReducer
from
"
./reducers/moraSlice
"
;
import
duelReducer
from
"
./reducers/duel/mod
"
;
import
cardsReducer
from
"
./reducers/cardsSlice
"
;
export
const
store
=
configureStore
({
reducer
:
{
...
...
@@ -15,6 +16,7 @@ export const store = configureStore({
player
:
playerReducer
,
mora
:
moraReducer
,
duel
:
duelReducer
,
cards
:
cardsReducer
,
},
});
...
...
src/ui/WaitRoom.tsx
View file @
90dbb589
...
...
@@ -4,7 +4,7 @@
* */
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
{
Link
,
useParams
}
from
"
react-router-dom
"
;
import
{
fetchDeck
}
from
"
../api/
Card
"
;
import
{
fetchDeck
}
from
"
../api/
deck
"
;
import
"
../css/WaitRoom.css
"
;
import
{
useAppSelector
}
from
"
../hook
"
;
import
{
selectJoined
}
from
"
../reducers/joinSlice
"
;
...
...
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