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
72a57075
Commit
72a57075
authored
Aug 13, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move forbiddens from store to api
parent
3845eb27
Pipeline
#23048
passed with stages
in 14 minutes and 25 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
25 deletions
+115
-25
src/api/forbiddens.ts
src/api/forbiddens.ts
+83
-0
src/api/index.ts
src/api/index.ts
+1
-0
src/stores/forbiddenStore.ts
src/stores/forbiddenStore.ts
+26
-17
src/stores/index.ts
src/stores/index.ts
+0
-3
src/ui/BuildDeck/index.tsx
src/ui/BuildDeck/index.tsx
+5
-5
No files found.
src/api/forbiddens.ts
0 → 100644
View file @
72a57075
//! 禁限卡表
import
{
clear
,
createStore
,
get
,
set
}
from
"
idb-keyval
"
;
import
{
useConfig
}
from
"
@/config
"
;
const
{
lflistUrl
}
=
useConfig
();
type
Forbiddens
=
Map
<
number
,
number
>
;
const
IDB_NAME
=
"
forbiddens
"
;
// 禁限卡表的时间,比如 [2023.4] - 2023年4月表
export
let
forbiddenTime
=
"
?
"
;
const
idb
=
createStore
(
IDB_NAME
,
IDB_NAME
);
export
async
function
initForbiddens
():
Promise
<
void
>
{
const
text
=
await
(
await
fetch
(
lflistUrl
)).
text
();
const
{
time
,
forbiddens
}
=
extractForbiddensFromText
(
text
);
forbiddenTime
=
time
;
// 先清掉之前的记录
clear
(
idb
);
// 设置新记录
await
Promise
.
all
(
Array
.
from
(
forbiddens
).
map
(([
key
,
value
])
=>
set
(
key
,
value
,
idb
))
);
}
// 获取禁限信息
export
async
function
getForbiddenInfo
(
id
:
number
):
Promise
<
number
|
undefined
>
{
return
await
get
(
id
,
idb
);
}
// 解析函数,提取卡片编号和限制张数
function
parseCardInfo
(
input
:
string
):
{
cardId
:
number
;
limitCount
:
number
}
|
null
{
const
match
=
input
.
match
(
/^
(\d
+
)\s
+
(\d
+
)\s
+--/
);
if
(
match
)
{
const
cardId
=
parseInt
(
match
[
1
]);
const
limitCount
=
parseInt
(
match
[
2
]);
return
{
cardId
,
limitCount
};
}
return
null
;
}
// 分割文本为行,并提取每行的限制信息
function
extractForbiddensFromText
(
text
:
string
):
{
time
:
string
;
forbiddens
:
Forbiddens
;
}
{
const
lines
=
text
.
split
(
"
\n
"
);
const
forbiddens
=
new
Map
<
number
,
number
>
([]);
// remove first line
lines
.
shift
();
let
time
=
"
?
"
;
for
(
const
line
of
lines
)
{
if
(
line
.
startsWith
(
"
#
"
))
{
// do nothing
}
else
if
(
line
.
startsWith
(
"
!
"
))
{
if
(
time
!==
"
?
"
)
{
// 已经读取完第一个禁限表的信息了,退出循环
break
;
}
else
{
time
=
line
.
substring
(
1
).
trim
();
}
}
else
{
const
cardInfo
=
parseCardInfo
(
line
);
if
(
cardInfo
)
{
forbiddens
.
set
(
cardInfo
.
cardId
,
cardInfo
.
limitCount
);
}
}
}
return
{
time
,
forbiddens
};
}
src/api/index.ts
View file @
72a57075
export
*
from
"
./cards
"
;
export
*
from
"
./cards
"
;
export
*
from
"
./cookies
"
;
export
*
from
"
./cookies
"
;
export
*
from
"
./forbiddens
"
;
export
*
from
"
./mycard
"
;
export
*
from
"
./mycard
"
;
export
*
from
"
./ocgcore/idl/ocgcore
"
;
export
*
from
"
./ocgcore/idl/ocgcore
"
;
export
*
from
"
./ocgcore/ocgHelper
"
;
export
*
from
"
./ocgcore/ocgHelper
"
;
...
...
src/stores/forbiddenStore.ts
View file @
72a57075
//! 禁
卡表Store
//! 禁
限卡表
import
{
proxy
}
from
"
valtio
"
;
import
{
clear
,
createStore
,
get
,
set
}
from
"
idb-keyval
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
useConfig
}
from
"
@/config
"
;
...
@@ -8,20 +8,31 @@ const { lflistUrl } = useConfig();
...
@@ -8,20 +8,31 @@ const { lflistUrl } = useConfig();
type
Forbiddens
=
Map
<
number
,
number
>
;
type
Forbiddens
=
Map
<
number
,
number
>
;
class
ForbiddenStore
{
const
IDB_NAME
=
"
forbiddens
"
;
time
:
string
=
"
?
"
;
inner
:
Forbiddens
=
new
Map
([]);
async
init
()
{
const
text
=
await
(
await
fetch
(
lflistUrl
)).
text
();
const
{
time
,
forbiddens
}
=
extractForbiddensFromText
(
text
);
this
.
time
=
time
;
this
.
inner
=
forbiddens
;
}
// 获取禁限信息
// 禁限卡表的时间,比如 [2023.4] - 2023年4月表
get
(
id
:
number
)
{
export
let
forbiddenTime
=
"
?
"
;
return
this
.
inner
.
get
(
id
);
}
const
idb
=
createStore
(
IDB_NAME
,
IDB_NAME
);
export
async
function
init
():
Promise
<
void
>
{
const
text
=
await
(
await
fetch
(
lflistUrl
)).
text
();
const
{
time
,
forbiddens
}
=
extractForbiddensFromText
(
text
);
forbiddenTime
=
time
;
// 先清掉之前的记录
clear
(
idb
);
// 设置新记录
await
Promise
.
all
(
Array
.
from
(
forbiddens
).
map
(([
key
,
value
])
=>
set
(
key
,
value
,
idb
))
);
}
// 获取禁限信息
export
async
function
getForbiddenInfo
(
id
:
number
):
Promise
<
number
|
undefined
>
{
return
await
get
(
id
,
idb
);
}
}
// 解析函数,提取卡片编号和限制张数
// 解析函数,提取卡片编号和限制张数
...
@@ -70,5 +81,3 @@ function extractForbiddensFromText(text: string): {
...
@@ -70,5 +81,3 @@ function extractForbiddensFromText(text: string): {
return
{
time
,
forbiddens
};
return
{
time
,
forbiddens
};
}
}
export
const
forbiddenStore
=
proxy
(
new
ForbiddenStore
());
src/stores/index.ts
View file @
72a57075
...
@@ -2,7 +2,6 @@ export * from "./accountStore";
...
@@ -2,7 +2,6 @@ export * from "./accountStore";
export
*
from
"
./cardStore
"
;
export
*
from
"
./cardStore
"
;
export
*
from
"
./chatStore
"
;
export
*
from
"
./chatStore
"
;
export
*
from
"
./deckStore
"
;
export
*
from
"
./deckStore
"
;
export
*
from
"
./forbiddenStore
"
;
export
*
from
"
./initStore
"
;
export
*
from
"
./initStore
"
;
export
*
from
"
./matStore
"
;
export
*
from
"
./matStore
"
;
export
*
from
"
./placeStore
"
;
export
*
from
"
./placeStore
"
;
...
@@ -17,7 +16,6 @@ import { accountStore } from "./accountStore";
...
@@ -17,7 +16,6 @@ import { accountStore } from "./accountStore";
import
{
cardStore
}
from
"
./cardStore
"
;
import
{
cardStore
}
from
"
./cardStore
"
;
import
{
chatStore
}
from
"
./chatStore
"
;
import
{
chatStore
}
from
"
./chatStore
"
;
import
{
deckStore
}
from
"
./deckStore
"
;
import
{
deckStore
}
from
"
./deckStore
"
;
import
{
forbiddenStore
}
from
"
./forbiddenStore
"
;
import
{
initStore
}
from
"
./initStore
"
;
import
{
initStore
}
from
"
./initStore
"
;
import
{
matStore
}
from
"
./matStore
"
;
import
{
matStore
}
from
"
./matStore
"
;
import
{
placeStore
}
from
"
./placeStore
"
;
import
{
placeStore
}
from
"
./placeStore
"
;
...
@@ -35,7 +33,6 @@ devtools(accountStore, { name: "account", enabled: DEV });
...
@@ -35,7 +33,6 @@ devtools(accountStore, { name: "account", enabled: DEV });
devtools
(
roomStore
,
{
name
:
"
room
"
,
enabled
:
DEV
});
devtools
(
roomStore
,
{
name
:
"
room
"
,
enabled
:
DEV
});
devtools
(
deckStore
,
{
name
:
"
deck
"
,
enabled
:
DEV
});
devtools
(
deckStore
,
{
name
:
"
deck
"
,
enabled
:
DEV
});
devtools
(
initStore
,
{
name
:
"
init
"
,
enabled
:
DEV
});
devtools
(
initStore
,
{
name
:
"
init
"
,
enabled
:
DEV
});
devtools
(
forbiddenStore
,
{
name
:
"
forbidden
"
,
enabled
:
DEV
});
// 重置`Store`
// 重置`Store`
export
const
resetUniverse
=
()
=>
{
export
const
resetUniverse
=
()
=>
{
...
...
src/ui/BuildDeck/index.tsx
View file @
72a57075
...
@@ -26,10 +26,10 @@ import { LoaderFunction } from "react-router-dom";
...
@@ -26,10 +26,10 @@ import { LoaderFunction } from "react-router-dom";
import
{
useSnapshot
}
from
"
valtio
"
;
import
{
useSnapshot
}
from
"
valtio
"
;
import
{
subscribeKey
}
from
"
valtio/utils
"
;
import
{
subscribeKey
}
from
"
valtio/utils
"
;
import
{
type
CardMeta
,
searchCards
}
from
"
@/api
"
;
import
{
type
CardMeta
,
initForbiddens
,
searchCards
}
from
"
@/api
"
;
import
{
isExtraDeckCard
,
isToken
}
from
"
@/common
"
;
import
{
isExtraDeckCard
,
isToken
}
from
"
@/common
"
;
import
{
FtsConditions
}
from
"
@/middleware/sqlite/fts
"
;
import
{
FtsConditions
}
from
"
@/middleware/sqlite/fts
"
;
import
{
deckStore
,
forbiddenStore
,
type
IDeck
,
initStore
}
from
"
@/stores
"
;
import
{
deckStore
,
type
IDeck
,
initStore
}
from
"
@/stores
"
;
import
{
import
{
Background
,
Background
,
IconFont
,
IconFont
,
...
@@ -40,9 +40,9 @@ import {
...
@@ -40,9 +40,9 @@ import {
import
{
CardDetail
}
from
"
./CardDetail
"
;
import
{
CardDetail
}
from
"
./CardDetail
"
;
import
{
DeckSelect
}
from
"
./DeckSelect
"
;
import
{
DeckSelect
}
from
"
./DeckSelect
"
;
import
{
editDeckStore
}
from
"
./store
"
;
import
{
Filter
}
from
"
./Filter
"
;
import
{
Filter
}
from
"
./Filter
"
;
import
styles
from
"
./index.module.scss
"
;
import
styles
from
"
./index.module.scss
"
;
import
{
editDeckStore
}
from
"
./store
"
;
import
{
editingDeckToIDeck
,
iDeckToEditingDeck
,
type
Type
}
from
"
./utils
"
;
import
{
editingDeckToIDeck
,
iDeckToEditingDeck
,
type
Type
}
from
"
./utils
"
;
export
const
loader
:
LoaderFunction
=
async
()
=>
{
export
const
loader
:
LoaderFunction
=
async
()
=>
{
...
@@ -53,8 +53,8 @@ export const loader: LoaderFunction = async () => {
...
@@ -53,8 +53,8 @@ export const loader: LoaderFunction = async () => {
});
});
}
}
//
加载
禁限卡表
//
更新
禁限卡表
await
forbiddenStore
.
init
();
await
initForbiddens
();
return
null
;
return
null
;
};
};
...
...
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