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
367ed2cb
Commit
367ed2cb
authored
Aug 12, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Move canAdd methods inside editDeckStore
parent
9b247064
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
48 deletions
+43
-48
src/ui/BuildDeck/editDeckStore.ts
src/ui/BuildDeck/editDeckStore.ts
+39
-1
src/ui/BuildDeck/index.tsx
src/ui/BuildDeck/index.tsx
+4
-9
src/ui/BuildDeck/utils.ts
src/ui/BuildDeck/utils.ts
+0
-38
No files found.
src/ui/BuildDeck/editDeckStore.ts
View file @
367ed2cb
...
@@ -3,12 +3,18 @@ import { proxy } from "valtio";
...
@@ -3,12 +3,18 @@ import { proxy } from "valtio";
import
{
type
CardMeta
}
from
"
@/api
"
;
import
{
type
CardMeta
}
from
"
@/api
"
;
import
{
compareCards
,
type
EditingDeck
,
type
Type
}
from
"
./utils
"
;
import
{
compareCards
,
type
EditingDeck
,
type
Type
}
from
"
./utils
"
;
import
{
isExtraDeckCard
,
isToken
}
from
"
@/common
"
;
export
const
editDeckStore
=
proxy
({
export
const
editDeckStore
=
proxy
({
deckName
:
""
,
deckName
:
""
,
main
:
[]
as
CardMeta
[],
main
:
[]
as
CardMeta
[],
extra
:
[]
as
CardMeta
[],
extra
:
[]
as
CardMeta
[],
side
:
[]
as
CardMeta
[],
side
:
[]
as
CardMeta
[],
// 标脏
edited
:
false
,
// 方法
add
(
type
:
Type
,
card
:
CardMeta
)
{
add
(
type
:
Type
,
card
:
CardMeta
)
{
editDeckStore
[
type
].
push
(
card
);
editDeckStore
[
type
].
push
(
card
);
editDeckStore
[
type
].
sort
(
compareCards
);
editDeckStore
[
type
].
sort
(
compareCards
);
...
@@ -34,5 +40,37 @@ export const editDeckStore = proxy({
...
@@ -34,5 +40,37 @@ export const editDeckStore = proxy({
editDeckStore
.
side
=
[];
editDeckStore
.
side
=
[];
editDeckStore
.
edited
=
true
;
editDeckStore
.
edited
=
true
;
},
},
edited
:
false
,
/** 一张卡能不能放入某个区 */
canAdd
(
card
:
CardMeta
,
type
:
Type
):
{
result
:
boolean
;
reason
:
string
}
{
let
result
=
true
,
reason
=
""
;
const
initialCards
=
editDeckStore
[
type
];
// 如果是衍生物,则不能添加
if
(
isToken
(
card
.
data
.
type
??
0
))
{
result
=
false
;
reason
=
"
不能添加衍生物
"
;
}
// 超出数量,则不能添加
const
countLimit
=
type
===
"
main
"
?
60
:
15
;
if
(
initialCards
.
length
>=
countLimit
)
{
result
=
false
;
reason
=
`超过
${
countLimit
}
张的上限`
;
}
// 接着需要检查卡的种类
if
(
(
type
===
"
extra
"
&&
!
isExtraDeckCard
(
card
.
data
.
type
??
0
))
||
(
type
===
"
main
"
&&
isExtraDeckCard
(
card
.
data
.
type
??
0
))
)
{
result
=
false
;
reason
=
"
卡片种类不符合
"
;
}
// 同名卡不超过三张
const
maxSameCard
=
3
;
// TODO: 禁卡表
const
sameCardCount
=
initialCards
.
filter
((
c
)
=>
c
.
id
===
card
.
id
).
length
;
if
(
sameCardCount
>=
maxSameCard
)
{
result
=
false
;
reason
=
`超过同名卡
${
maxSameCard
}
张的上限`
;
}
return
{
result
,
reason
};
},
})
satisfies
EditingDeck
;
})
satisfies
EditingDeck
;
src/ui/BuildDeck/index.tsx
View file @
367ed2cb
...
@@ -44,12 +44,7 @@ import { DeckSelect } from "./DeckSelect";
...
@@ -44,12 +44,7 @@ import { DeckSelect } from "./DeckSelect";
import
{
editDeckStore
}
from
"
./editDeckStore
"
;
import
{
editDeckStore
}
from
"
./editDeckStore
"
;
import
{
Filter
}
from
"
./Filter
"
;
import
{
Filter
}
from
"
./Filter
"
;
import
styles
from
"
./index.module.scss
"
;
import
styles
from
"
./index.module.scss
"
;
import
{
import
{
editingDeckToIDeck
,
iDeckToEditingDeck
,
type
Type
}
from
"
./utils
"
;
canAdd
,
editingDeckToIDeck
,
iDeckToEditingDeck
,
type
Type
,
}
from
"
./utils
"
;
const
theme
:
ThemeConfig
=
{
const
theme
:
ThemeConfig
=
{
components
:
{
components
:
{
...
@@ -368,7 +363,7 @@ const DeckZone: React.FC<{
...
@@ -368,7 +363,7 @@ const DeckZone: React.FC<{
// 当拖拽物在这个拖放区域放下时触发,这个item就是拖拽物的item(拖拽物携带的数据)
// 当拖拽物在这个拖放区域放下时触发,这个item就是拖拽物的item(拖拽物携带的数据)
drop
:
({
value
,
source
}:
{
value
:
CardMeta
;
source
:
Type
|
"
search
"
})
=>
{
drop
:
({
value
,
source
}:
{
value
:
CardMeta
;
source
:
Type
|
"
search
"
})
=>
{
if
(
type
===
source
)
return
;
if
(
type
===
source
)
return
;
const
{
result
,
reason
}
=
canAdd
(
value
,
type
,
editDeckStor
e
);
const
{
result
,
reason
}
=
editDeckStore
.
canAdd
(
value
,
typ
e
);
if
(
result
)
{
if
(
result
)
{
editDeckStore
.
add
(
type
,
value
);
editDeckStore
.
add
(
type
,
value
);
if
(
source
!==
"
search
"
)
{
if
(
source
!==
"
search
"
)
{
...
@@ -380,7 +375,7 @@ const DeckZone: React.FC<{
...
@@ -380,7 +375,7 @@ const DeckZone: React.FC<{
},
},
hover
:
({
value
,
source
})
=>
{
hover
:
({
value
,
source
})
=>
{
setAllowToDrop
(
setAllowToDrop
(
type
!==
source
?
canAdd
(
value
,
type
,
editDeckStor
e
).
result
:
true
type
!==
source
?
editDeckStore
.
canAdd
(
value
,
typ
e
).
result
:
true
);
);
},
},
collect
:
(
monitor
)
=>
({
collect
:
(
monitor
)
=>
({
...
@@ -416,7 +411,7 @@ const SearchResults: React.FC<{
...
@@ -416,7 +411,7 @@ const SearchResults: React.FC<{
}
>
=
memo
(({
results
})
=>
{
}
>
=
memo
(({
results
})
=>
{
const
handleClick
=
(
card
:
CardMeta
)
=>
{
const
handleClick
=
(
card
:
CardMeta
)
=>
{
const
type
=
isExtraDeckCard
(
card
.
data
.
type
??
0
)
?
"
extra
"
:
"
main
"
;
const
type
=
isExtraDeckCard
(
card
.
data
.
type
??
0
)
?
"
extra
"
:
"
main
"
;
canAdd
(
card
,
type
,
editDeckStor
e
).
result
&&
editDeckStore
.
add
(
type
,
card
);
editDeckStore
.
canAdd
(
card
,
typ
e
).
result
&&
editDeckStore
.
add
(
type
,
card
);
};
};
return
(
return
(
<
div
className=
{
styles
[
"
search-cards
"
]
}
>
<
div
className=
{
styles
[
"
search-cards
"
]
}
>
...
...
src/ui/BuildDeck/utils.ts
View file @
367ed2cb
...
@@ -28,44 +28,6 @@ export const editingDeckToIDeck = (deck: EditingDeck): IDeck => ({
...
@@ -28,44 +28,6 @@ export const editingDeckToIDeck = (deck: EditingDeck): IDeck => ({
side
:
deck
.
side
.
map
((
card
)
=>
card
.
id
),
side
:
deck
.
side
.
map
((
card
)
=>
card
.
id
),
});
});
/** 能不能添加到正在编辑的卡组的区域 */
export
const
canAdd
=
(
card
:
CardMeta
,
type
:
Type
,
editDeckStore
:
EditingDeck
):
{
result
:
boolean
;
reason
?:
string
}
=>
{
let
result
=
true
,
reason
;
const
initialCards
=
editDeckStore
[
type
];
// 如果是衍生物,则不能添加
if
(
isToken
(
card
.
data
.
type
??
0
))
{
result
=
false
;
reason
=
"
不能添加衍生物
"
;
}
// 超出数量,则不能添加
const
countLimit
=
type
===
"
main
"
?
60
:
15
;
if
(
initialCards
.
length
>=
countLimit
)
{
result
=
false
;
reason
=
`超过
${
countLimit
}
张的上限`
;
}
// 接着需要检查卡的种类
if
(
(
type
===
"
extra
"
&&
!
isExtraDeckCard
(
card
.
data
.
type
??
0
))
||
(
type
===
"
main
"
&&
isExtraDeckCard
(
card
.
data
.
type
??
0
))
)
{
result
=
false
;
reason
=
"
卡片种类不符合
"
;
}
// 同名卡不超过三张
const
maxSameCard
=
3
;
// TODO: 禁卡表
const
sameCardCount
=
initialCards
.
filter
((
c
)
=>
c
.
id
===
card
.
id
).
length
;
if
(
sameCardCount
>=
maxSameCard
)
{
result
=
false
;
reason
=
`超过同名卡
${
maxSameCard
}
张的上限`
;
}
return
{
result
,
reason
};
};
/** 卡组内部排序,给array.sort用 */
/** 卡组内部排序,给array.sort用 */
export
const
compareCards
=
(
a
:
CardMeta
,
b
:
CardMeta
):
number
=>
{
export
const
compareCards
=
(
a
:
CardMeta
,
b
:
CardMeta
):
number
=>
{
const
aType
=
tellCardBasicType
(
a
.
data
.
type
??
0
);
const
aType
=
tellCardBasicType
(
a
.
data
.
type
??
0
);
...
...
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