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
baichixing
Neos
Commits
ec305a4e
Commit
ec305a4e
authored
Aug 16, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: forbidden
parent
ee7feabe
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
56 deletions
+76
-56
src/api/forbiddens.ts
src/api/forbiddens.ts
+63
-51
src/stores/initStore.ts
src/stores/initStore.ts
+2
-1
src/ui/BuildDeck/CardDetail.tsx
src/ui/BuildDeck/CardDetail.tsx
+1
-1
src/ui/BuildDeck/index.tsx
src/ui/BuildDeck/index.tsx
+8
-3
src/ui/Layout/index.tsx
src/ui/Layout/index.tsx
+2
-0
No files found.
src/api/forbiddens.ts
View file @
ec305a4e
import
{
useConfig
}
from
"
@/config
"
;
import
{
initStore
}
from
"
@/stores
"
;
const
{
lflistUrl
}
=
useConfig
();
type
Forbiddens
=
Map
<
number
,
number
>
;
class
Forbidden
{
private
data
:
Map
<
number
,
number
>
=
new
Map
<
number
,
number
>
();
public
time
:
string
=
"
?
"
;
export
let
forbiddenTime
=
"
?
"
;
export
async
function
initForbiddens
():
Promise
<
void
>
{
public
async
init
():
Promise
<
void
>
{
const
text
=
await
(
await
fetch
(
lflistUrl
)).
text
();
const
{
time
,
forbiddens
}
=
extractForbiddensFromText
(
text
);
forbiddenTime
=
time
;
setForbiddens
(
forbiddens
);
}
const
{
time
,
forbiddens
}
=
this
.
extractForbiddensFromText
(
text
);
this
.
time
=
time
;
this
.
setForbiddens
(
forbiddens
);
initStore
.
forbidden
=
true
;
}
const
forbiddensMap
:
Forbiddens
=
new
Map
<
number
,
number
>
();
public
set
(
cardId
:
number
,
limitCount
:
number
):
void
{
this
.
data
.
set
(
cardId
,
limitCount
);
}
function
setForbiddens
(
forbiddens
:
Forbiddens
):
void
{
forbiddensMap
.
clear
();
for
(
const
[
cardId
,
limitCount
]
of
forbiddens
)
{
forbiddensMap
.
set
(
cardId
,
limitCount
);
public
get
(
id
:
number
):
number
|
undefined
{
return
this
.
data
.
get
(
id
);
}
}
export
function
getForbiddenInfo
(
id
:
number
):
number
|
undefined
{
return
forbiddensMap
.
get
(
id
);
}
private
setForbiddens
(
forbiddens
:
Map
<
number
,
number
>
):
void
{
this
.
data
.
clear
();
for
(
const
[
cardId
,
limitCount
]
of
forbiddens
)
{
this
.
data
.
set
(
cardId
,
limitCount
);
}
}
function
extractForbiddensFromText
(
text
:
string
):
{
private
extractForbiddensFromText
(
text
:
string
):
{
time
:
string
;
forbiddens
:
Forbiddens
;
}
{
forbiddens
:
Map
<
number
,
number
>
;
}
{
// 解析文本行中的卡片信息
function
parseCardInfo
(
input
:
string
,
):
{
cardId
:
number
;
limitCount
:
number
}
|
null
{
...
...
@@ -41,30 +46,37 @@ function extractForbiddensFromText(text: string): {
}
return
null
;
}
const
lines
=
text
.
split
(
"
\n
"
);
const
forbiddens
=
new
Map
<
number
,
number
>
();
lines
.
shift
();
// remove first line
let
time
=
"
?
"
;
// 移除第一行标题
lines
.
shift
();
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
};
}
}
export
const
forbidden
=
new
Forbidden
();
src/stores/initStore.ts
View file @
ec305a4e
...
...
@@ -5,10 +5,11 @@ import { type NeosStore } from "./shared";
export
const
initStore
=
proxy
({
sqlite
:
{
progress
:
0
,
// 0 -> 1
},
},
// ygodb
decks
:
false
,
i18n
:
false
,
wasm
:
false
,
forbidden
:
false
,
// 禁卡表
// ...
reset
()
{},
}
satisfies
NeosStore
);
src/ui/BuildDeck/CardDetail.tsx
View file @
ec305a4e
...
...
@@ -8,9 +8,9 @@ import {
extraCardTypes
,
isLinkMonster
,
isMonster
,
isPendulumMonster
,
Race2StringCodeMap
,
Type2StringCodeMap
,
isPendulumMonster
,
}
from
"
@/common
"
;
import
{
CardEffectText
,
IconFont
,
ScrollableArea
,
YgoCard
}
from
"
@/ui/Shared
"
;
...
...
src/ui/BuildDeck/index.tsx
View file @
ec305a4e
...
...
@@ -26,7 +26,7 @@ import { LoaderFunction } from "react-router-dom";
import
{
proxy
,
useSnapshot
}
from
"
valtio
"
;
import
{
subscribeKey
}
from
"
valtio/utils
"
;
import
{
type
CardMeta
,
initForbiddens
,
searchCards
}
from
"
@/api
"
;
import
{
type
CardMeta
,
searchCards
}
from
"
@/api
"
;
import
{
isToken
}
from
"
@/common
"
;
import
{
FtsConditions
}
from
"
@/middleware/sqlite/fts
"
;
import
{
deckStore
,
type
IDeck
,
initStore
}
from
"
@/stores
"
;
...
...
@@ -59,8 +59,13 @@ export const loader: LoaderFunction = async () => {
});
}
// 更新禁限卡表
await
initForbiddens
();
// 同时,等待禁卡表的加载
if
(
!
initStore
.
forbidden
)
{
await
new
Promise
<
void
>
((
rs
)
=>
{
subscribeKey
(
initStore
,
"
forbidden
"
,
(
done
)
=>
done
&&
rs
());
});
}
return
null
;
};
...
...
src/ui/Layout/index.tsx
View file @
ec305a4e
...
...
@@ -9,6 +9,7 @@ import {
}
from
"
react-router-dom
"
;
import
{
useSnapshot
}
from
"
valtio
"
;
import
{
forbidden
}
from
"
@/api
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
accountStore
}
from
"
@/stores
"
;
...
...
@@ -28,6 +29,7 @@ export const loader: LoaderFunction = async () => {
initDeck
();
initSqlite
();
initWASM
();
forbidden
.
init
();
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