Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
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
syntax_j
mycard
Commits
c818af1c
Commit
c818af1c
authored
Aug 26, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use regex match for last deck
parent
44d0ba96
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
8 deletions
+66
-8
app/ygopro.component.ts
app/ygopro.component.ts
+66
-8
No files found.
app/ygopro.component.ts
View file @
c818af1c
...
...
@@ -93,7 +93,15 @@ export interface Points {
ratio
:
number
;
}
interface
YGOProDistroData
{
deckPath
:
string
;
replayPath
:
string
;
systemConf
?:
string
;
lastDeckFormat
?:
string
;
}
interface
YGOProData
{
ygopro
:
YGOProDistroData
;
servers
:
Server
[];
}
...
...
@@ -148,6 +156,8 @@ export class YGOProComponent implements OnInit, OnDestroy {
// tslint:disable-next-line:member-ordering
rooms_loading
=
true
;
lastDeckFormat
:
RegExp
;
default_options
:
Options
=
{
mode
:
1
,
rule
:
this
.
settingsService
.
getLocale
().
startsWith
(
'
zh
'
)
?
0
:
1
,
...
...
@@ -269,7 +279,8 @@ export class YGOProComponent implements OnInit, OnDestroy {
}
async
ngOnInit
()
{
this
.
servers
=
(
<
YGOProData
>
this
.
app
.
data
).
servers
;
const
ygoproData
=
<
YGOProData
>
this
.
app
.
data
;
this
.
servers
=
ygoproData
.
servers
;
this
.
selectableServers
=
this
.
servers
.
filter
(
s
=>
!
s
.
hidden
);
this
.
currentServer
=
this
.
selectableServers
[
0
];
// this.reloadCurrentServer();
...
...
@@ -281,6 +292,11 @@ export class YGOProComponent implements OnInit, OnDestroy {
locale
=
'
en-US
'
;
}
if
(
ygoproData
.
ygopro
.
lastDeckFormat
)
{
//console.log(`Deck format pattern: ${ygoproData.ygopro.lastDeckFormat}`)
this
.
lastDeckFormat
=
new
RegExp
(
ygoproData
.
ygopro
.
lastDeckFormat
);
}
this
.
system_conf
=
this
.
app
.
systemConfPath
;
await
this
.
refresh
(
true
);
...
...
@@ -408,12 +424,29 @@ export class YGOProComponent implements OnInit, OnDestroy {
async
refresh
(
init
?:
boolean
)
{
this
.
decks
=
await
this
.
get_decks
();
let
system_conf
=
await
this
.
load_system_conf
();
if
(
this
.
lastDeckFormat
)
{
const
systemConfString
=
await
this
.
load_system_conf
();
let
lastDeck
:
string
;
if
(
systemConfString
)
{
// console.log(`System conf string: ${systemConfString}`);
const
lastDeckMatch
=
systemConfString
.
match
(
this
.
lastDeckFormat
);
if
(
lastDeckMatch
)
{
lastDeck
=
lastDeckMatch
[
1
];
// console.log(`Last deck ${lastDeck} read from ${this.system_conf}.`);
}
else
{
// console.error(`Deck pattern not found from pattern ${this.system_conf}: ${lastDeckMatch}`);
}
}
else
{
// console.error(`System conf ${this.system_conf} not found.`);
}
if
(
system_conf
&&
this
.
decks
.
includes
(
system_conf
.
lastdeck
))
{
this
.
current_deck
=
system_conf
.
lastdeck
;
}
else
if
(
init
)
{
this
.
current_deck
=
this
.
decks
[
0
];
if
(
lastDeck
&&
this
.
decks
.
includes
(
lastDeck
))
{
// console.log(`Got last deck ${lastDeck}.`);
this
.
current_deck
=
lastDeck
;
}
else
if
(
init
)
{
this
.
current_deck
=
this
.
decks
[
0
];
}
}
this
.
replays
=
await
this
.
get_replays
();
...
...
@@ -435,9 +468,33 @@ export class YGOProComponent implements OnInit, OnDestroy {
async
get_decks
():
Promise
<
string
[]
>
{
try
{
/*
const deckPath = this.app.ygoproDeckPath;
let result: string[] = [];
const files: string[] = await fs.readdir(deckPath);
for (const file of files) {
if (file.startsWith('.git')) { // fuck
continue;
}
if (path.extname(file) === '.ydk') {
result.push(path.basename(file, '.ydk'));
} else {
const fullPath = path.join(deckPath, file);
const stat = await fs.stat(fullPath);
if (stat.isDirectory()) {
const innerDecks = (await fs.readdir(fullPath))
.filter((iFile) => path.extname(iFile) === '.ydk')
.map((iFile) => path.join(file, path.basename(iFile, '.ydk')));
result = result.concat(innerDecks);
}
}
}
return result;
*/
let
files
:
string
[]
=
await
fs
.
readdir
(
this
.
app
.
ygoproDeckPath
);
return
files
.
filter
(
file
=>
path
.
extname
(
file
)
===
'
.ydk
'
).
map
(
file
=>
path
.
basename
(
file
,
'
.ydk
'
));
}
catch
(
error
)
{
console
.
error
(
`Load deck fail:
${
error
.
toString
()}
`
);
return
[];
}
}
...
...
@@ -447,6 +504,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
let
files
:
string
[]
=
await
fs
.
readdir
(
this
.
app
.
ygoproReplayPath
);
return
files
.
filter
(
file
=>
path
.
extname
(
file
)
===
'
.yrp
'
).
map
(
file
=>
path
.
basename
(
file
,
'
.yrp
'
));
}
catch
(
error
)
{
console
.
error
(
`Load replay fail:
${
error
.
toString
()}
`
);
return
[];
}
}
...
...
@@ -486,13 +544,13 @@ export class YGOProComponent implements OnInit, OnDestroy {
}
};*/
async
load_system_conf
():
Promise
<
SystemConf
>
{
async
load_system_conf
():
Promise
<
string
>
{
if
(
!
this
.
system_conf
)
{
return
null
;
}
try
{
let
data
=
await
fs
.
readFile
(
this
.
system_conf
,
{
encoding
:
'
utf-8
'
});
return
<
any
>
ini
.
parse
(
data
)
;
return
data
;
}
catch
(
e
)
{
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