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
46a685a2
Commit
46a685a2
authored
Oct 21, 2016
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deck edit
parent
a349dda6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
18 deletions
+66
-18
app/ygopro.component.ts
app/ygopro.component.ts
+66
-18
No files found.
app/ygopro.component.ts
View file @
46a685a2
...
@@ -9,6 +9,7 @@ declare var process;
...
@@ -9,6 +9,7 @@ declare var process;
declare
var
System
;
declare
var
System
;
const
fs
=
System
.
_nodeRequire
(
'
fs
'
);
const
fs
=
System
.
_nodeRequire
(
'
fs
'
);
const
path
=
System
.
_nodeRequire
(
'
path
'
);
const
path
=
System
.
_nodeRequire
(
'
path
'
);
const
child_process
=
System
.
_nodeRequire
(
'
child_process
'
);
//const Promise = System._nodeRequire('bluebird');
//const Promise = System._nodeRequire('bluebird');
const
ini
=
System
.
_nodeRequire
(
'
ini
'
);
const
ini
=
System
.
_nodeRequire
(
'
ini
'
);
...
@@ -23,8 +24,8 @@ export class YGOProComponent {
...
@@ -23,8 +24,8 @@ export class YGOProComponent {
current_deck
;
current_deck
;
system_conf
=
path
.
join
(
this
.
app
.
local
.
path
,
'
system.conf
'
);
system_conf
=
path
.
join
(
this
.
app
.
local
.
path
,
'
system.conf
'
);
numfont
=
this
.
get_font
({
'
darwin
'
:
[
'
/System/Library/Fonts/PingFang.ttc
'
]})
;
numfont
=
{
'
darwin
'
:
[
'
/System/Library/Fonts/PingFang.ttc
'
]}
;
textfont
=
this
.
get_font
({
'
darwin
'
:
[
'
/System/Library/Fonts/PingFang.ttc
'
]})
;
textfont
=
{
'
darwin
'
:
[
'
/System/Library/Fonts/PingFang.ttc
'
]}
;
constructor
(
private
appsService
:
AppsService
,
private
routingService
:
RoutingService
)
{
constructor
(
private
appsService
:
AppsService
,
private
routingService
:
RoutingService
)
{
this
.
refresh
()
this
.
refresh
()
...
@@ -39,18 +40,6 @@ export class YGOProComponent {
...
@@ -39,18 +40,6 @@ export class YGOProComponent {
})
})
}
}
get_font
(
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
fonts
=
data
[
process
.
platform
]
})
}
fix_fonts
(
ini
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
numfont
.
then
()
})
}
get_decks
():
Promise
<
[
string
]
>
{
get_decks
():
Promise
<
[
string
]
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
readdir
(
path
.
join
(
this
.
app
.
local
.
path
,
'
deck
'
),
(
error
,
files
)
=>
{
fs
.
readdir
(
path
.
join
(
this
.
app
.
local
.
path
,
'
deck
'
),
(
error
,
files
)
=>
{
...
@@ -63,10 +52,69 @@ export class YGOProComponent {
...
@@ -63,10 +52,69 @@ export class YGOProComponent {
})
})
}
}
get_font
(
files
:
string
[])
{
return
new
Promise
((
resolve
,
reject
)
=>
{
files
.
reduce
((
promise
,
file
:
string
)
=>
{
return
promise
.
then
(()
=>
file
).
then
(()
=>
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
access
(
file
,
fs
.
constants
.
R_OK
,
(
error
)
=>
{
error
?
resolve
(
`can't find fonts
${
files
[
process
.
platform
]}
`
)
:
reject
(
file
)
});
}));
},
Promise
.
resolve
()).
then
(
reject
,
resolve
);
})
}
edit_deck
(
deck
)
{
edit_deck
(
deck
)
{
fs
.
readFile
(
this
.
system_conf
,
{
encoding
:
'
utf-8
'
},
(
error
,
data
)
=>
{
this
.
load_system_conf
()
if
(
error
)
throw
error
;
.
then
(
this
.
fix_fonts
)
console
.
log
(
ini
.
parse
(
data
));
.
then
(
data
=>
{
});
data
[
'
lastdeck
'
]
=
deck
;
return
data
})
.
then
(
this
.
save_system_conf
)
.
then
(()
=>
[
'
-d
'
])
.
then
(
this
.
start_game
)
.
catch
(
reason
=>
console
.
log
(
reason
))
}
}
fix_fonts
=
(
data
)
=>
{
return
this
.
get_font
([
data
.
numfont
])
.
catch
(()
=>
this
.
get_font
(
this
.
numfont
[
process
.
platform
]).
then
(
font
=>
data
[
'
numfont
'
]
=
font
))
.
catch
()
.
then
(()
=>
this
.
get_font
([
data
.
textfont
.
split
(
'
'
,
2
)[
0
]]))
.
catch
(()
=>
this
.
get_font
(
this
.
textfont
[
process
.
platform
]).
then
(
font
=>
data
[
'
textfont
'
]
=
`
${
font
}
14`
))
.
catch
()
.
then
(()
=>
data
)
};
load_system_conf
=
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
readFile
(
this
.
system_conf
,
{
encoding
:
'
utf-8
'
},
(
error
,
data
)
=>
{
if
(
error
)
return
reject
(
error
);
resolve
(
ini
.
parse
(
data
));
});
})
};
save_system_conf
=
(
data
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
writeFile
(
this
.
system_conf
,
ini
.
stringify
(
data
,
{
whitespace
:
true
}),
(
error
)
=>
{
if
(
error
)
return
reject
(
error
);
resolve
(
data
);
});
})
};
start_game
=
(
args
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
child
=
child_process
.
spawn
(
path
.
join
(
this
.
app
.
local
.
path
,
this
.
app
.
actions
[
process
.
platform
][
'
main
'
][
'
execute
'
]),
args
,
{
cwd
:
this
.
app
.
local
.
path
});
child
.
on
(
'
error
'
,
(
error
)
=>
{
reject
(
error
)
});
child
.
on
(
'
exit
'
,
(
code
,
signal
)
=>
{
// error 触发之后还可能会触发exit,但是Promise只承认首次状态转移,因此这里无需重复判断是否已经error过。
resolve
(
code
)
})
})
};
}
}
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