Skip to content

Commit 529f599

Browse files
committed
Move to electron.
1 parent 5f70deb commit 529f599

15 files changed

+969
-190
lines changed

index.html

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
54
<meta charset=utf-8>
6-
7-
<title>
8-
crowdmap
9-
</title>
5+
<title>crowdmap</title>
106

117
<link href="style.css" rel="stylesheet" type="text/css">
12-
13-
<script src="js/es6-promise.min.js"></script>
14-
<script src="js/helpers.js"></script>
15-
<script src="js/rgbasm.js"></script>
16-
<script src="js/dialog.js"></script>
17-
<script src="js/config.js"></script>
18-
<script src="js/map_editor.js"></script>
19-
<script src="js/console.js"></script>
20-
<script src="js/error.js"></script>
21-
<script src="js/key.js"></script>
22-
238
</head>
249

2510
<body onload="main()">
2611
<div id="nojs">
2712
Turn javascript on.
2813
</div>
29-
<div id="errors" class="errors">
30-
</div>
31-
<div id="cursor_info" class="cursor_info">
32-
</div>
14+
<div id="errors" class="errors"></div>
15+
<div id="cursor_info" class="cursor_info"></div>
3316
</body>
17+
18+
<script src="js/es6-promise.min.js"></script>
19+
<script src="js/helpers.js"></script>
20+
<script src="js/key.js"></script>
21+
<script src="js/rgbasm.js"></script>
22+
<script src="js/dialog.js"></script>
23+
<script src="js/config.js"></script>
24+
<script src="js/map_editor.js"></script>
25+
<script src="js/console.js"></script>
26+
<script src="js/error.js"></script>
27+
28+
<script src="js/file.js"></script>
29+
<script src="js/settings.js"></script>
30+
<script src="js/task.js"></script>
31+
32+
<script src="js/pokecrystal.js"></script>
33+
34+
<script src="js/electron.js"></script>
3435
</html>

js/config.js

+93-40
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,70 @@
1-
var root = '../'
1+
var Config = {
2+
default: {
3+
version: 'pokecrystal',
4+
time: 'day',
5+
default_map: 'OlivineCity',
6+
paths: {
7+
map_data: 'maps',
8+
sprites: {
9+
npc: 'gfx/overworld',
10+
},
11+
12+
map_header: 'maps/map_headers.asm',
13+
map_header_2: 'maps/second_map_headers.asm',
14+
map_constants: 'constants/map_constants.asm',
15+
map_dimensions: 'constants/map_constants.asm',
16+
map_includes: 'maps.asm',
17+
},
18+
19+
tilesets: {
20+
roof_start: 0xa,
21+
},
22+
23+
misc: {
24+
max_blocks: 1300,
25+
},
26+
},
27+
}
28+
29+
30+
// TODO basically everything below this point needs to go into Config.default or pokecrystal.js
31+
232

333
var config = {
4-
root: root,
34+
root_path: '../',
535

636
time: 'day',
7-
default_map: 'OlivineCity',
37+
default_map: undefined,
838

9-
asm_dir: root + 'maps/',
10-
ow_dir: root + 'gfx/overworld/',
39+
get asm_dir () { return this.root_path + 'maps/' },
40+
get ow_dir () { return this.root_path + 'gfx/overworld/' },
1141

12-
map_header_path: root + 'maps/map_headers.asm',
13-
map_header_2_path: root + 'maps/second_map_headers.asm',
14-
map_constants_path: root + 'constants/map_constants.asm',
15-
map_dimensions_path: root + 'constants/map_constants.asm',
42+
get map_header_path () { return this.root_path + 'maps/map_headers.asm' },
43+
get map_header_2_path() { return this.root_path + 'maps/second_map_headers.asm' },
44+
get map_constants_path() { return this.root_path + 'constants/map_constants.asm' },
45+
get map_dimensions_path() { return this.root_path + 'constants/map_constants.asm' },
46+
get map_dimensions_path_prism() { return this.root_path + 'constants/map_dimension_constants.asm' },
1647

1748
roofs: [ -1, 3, 2, -1, 1, 2, -1, -1, 2, 2, 1, 4, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 3, -1, 0, -1, 0 ],
1849
//roof_permissions: [ 1, 'TOWN', 2, 'ROUTE', 4, 'CAVE' ], // wrong, see roof_tilesets
1950
roof_tilesets: [
2051
1, 'TILESET_JOHTO_1',
2152
2, 'TILESET_JOHTO_2',
2253
4, 'TILESET_BATTLE_TOWER_OUTSIDE',
54+
55+
// prism
56+
'TILESET_NALJO_1',
57+
'TILESET_NALJO_2',
2358
],
2459
roof_start: 0xa,
2560

2661
max_blocks: 1300,
2762

63+
read: function (path) {
64+
return File.readAsync(path)
65+
},
2866
getTilesetConstants: function () {
29-
return request(root + 'constants/tilemap_constants.asm')
67+
return this.read(this.root_path + 'constants/tilemap_constants.asm')
3068
.then(read_constants)
3169
.then(function (constants) {
3270
var filtered = {}
@@ -41,26 +79,29 @@ var config = {
4179
getTilesetId: function (name) {
4280
return this.getTilesetConstants()
4381
.then(function (constants) {
44-
return constants[name]
82+
return constants[name] || name
4583
})
4684
},
4785

4886
getTilesetImagePath: function (id) {
49-
return this.getTilesetId(id)
87+
var self = this
88+
return self.getTilesetId(id)
5089
.then(function (i) {
51-
return root + 'gfx/tilesets/' + zfill(i, 2) + '.png'
90+
return Path.resolve(self.root_path + 'gfx/tilesets/' + zfill(i, 2) + '.png')
5291
})
5392
},
5493

5594
getBlockdataPath: function (name) {
95+
var self = this
5696
var filenames = [
5797
'maps/blockdata_1.asm',
5898
'maps/blockdata_2.asm',
5999
'maps/blockdata_3.asm',
60100
'maps.asm', // newMap() dumps blockdata here
101+
'maps/blockdata.asm', // prism
61102
]
62-
return Promise.all(filenames.map(function (filename) {
63-
return request(root + filename)
103+
return Promise.some(filenames.map(function (filename) {
104+
return File.readAsync(self.root_path + filename)
64105
}))
65106
.then(function (texts) {
66107
var r = rgbasm.instance()
@@ -78,34 +119,42 @@ var config = {
78119
}
79120
for (var i = 0; i < texts.length; i++) {
80121
var text = texts[i]
81-
var result = r.read(text)
82-
if (result) return root + result
122+
if (text) {
123+
var result = r.read(text)
124+
if (result) {
125+
return self.root_path + result.replace(/\.lz$/, '')
126+
}
127+
}
83128
}
129+
130+
return Path.resolve(self.root_path + 'maps/' + name + '.blk')
84131
})
85132
},
86133

87134
getMetatilePath: function (id) {
88-
return this.getTilesetId(id)
135+
var self = this
136+
return self.getTilesetId(id)
89137
.then(function (i) {
90-
return root + 'tilesets/' + zfill(i, 2) + '_metatiles.bin'
138+
return self.root_path + 'tilesets/' + zfill(i, 2) + '_metatiles.bin'
91139
})
92140
},
93141
getPalmapPath: function (id) {
94-
return this.getTilesetId(id)
142+
var self = this
143+
return self.getTilesetId(id)
95144
.then(function (i) {
96-
return root + 'tilesets/' + zfill(i, 2) + '_palette_map.asm'
145+
return self.root_path + 'tilesets/' + zfill(i, 2) + '_palette_map.asm'
97146
})
98147
},
99-
getPalettePath: function () { return root + 'tilesets/bg.pal' },
100-
getObjectPalettePath: function () { return root + 'tilesets/ob.pal' },
101-
getRoofPalettePath: function () { return root + 'tilesets/roof.pal' },
148+
getPalettePath: function () { return this.root_path + 'tilesets/bg.pal' },
149+
getObjectPalettePath: function () { return this.root_path + 'tilesets/ob.pal' },
150+
getRoofPalettePath: function () { return this.root_path + 'tilesets/roof.pal' },
102151

103152
getRoofImagePath: function (group) {
104153
var roof = this.roofs[group]
105154
if (roof === -1 || typeof roof === 'undefined') {
106155
roof = 0
107156
}
108-
return root + 'gfx/tilesets/roofs/' + roof + '.png'
157+
return this.root_path + 'gfx/tilesets/roofs/' + roof + '.png'
109158
},
110159

111160
default_map_header: {
@@ -192,7 +241,7 @@ config.getNpcTiles = function (npc) {
192241
}
193242

194243
config.loadNpcGraphics = function (npc) {
195-
var pal_promise = request(config.getObjectPalettePath())
244+
var pal_promise = File.readAsync(config.getObjectPalettePath())
196245
.then(function (text) {
197246
var palettes = readPalette(text)
198247
var color = npc.color
@@ -212,7 +261,7 @@ config.loadNpcGraphics = function (npc) {
212261

213262
var image_promise = config.getSpritePath(npc.sprite)
214263
.then(function(path) {
215-
var image = newImage(path)
264+
var image = newImage(Path.resolve(path))
216265
return imagePromise(image)
217266
.then(function () { return image })
218267
})
@@ -419,11 +468,11 @@ function newImage (path) {
419468
}
420469

421470
function loadFacings() {
422-
return request(root + 'engine/facings.asm')
471+
return File.readAsync(config.root_path + 'engine/facings.asm')
423472
.then(parseFacings)
424473
.then(function (facings) {
425474
Object.update(Data.facings, facings)
426-
return request(root + 'constants/sprite_constants.asm')
475+
return File.readAsync(config.root_path + 'constants/sprite_constants.asm')
427476
.then(read_constants)
428477
})
429478
.then(function (constants) {
@@ -497,6 +546,7 @@ function parseFacings(text) {
497546
}
498547

499548
config.getSpritePath = function (constant) {
549+
var self = this
500550
return getSpriteConstants()
501551
.then(function (constants) {
502552
var sprite_id = constants[constant] - 1
@@ -506,12 +556,12 @@ config.getSpritePath = function (constant) {
506556
if (sprite_id > 102) {
507557
sprite_id = 0
508558
}
509-
return root + 'gfx/overworld/' + sprite_id.toString().zfill(3) + '.png'
559+
return self.root_path + 'gfx/overworld/' + sprite_id.toString().zfill(3) + '.png'
510560
})
511561
}
512562

513563
config.getMapEventPath = function (map_name) {
514-
return root + 'maps/' + map_name + '.asm'
564+
return this.root_path + 'maps/' + map_name + '.asm'
515565
}
516566

517567
config.readEvents = function (map_name) {
@@ -526,19 +576,22 @@ function getSpriteConstants() {
526576
}
527577

528578
function getSpriteConstantsText() {
529-
return request(root + 'constants/sprite_constants.asm')
579+
return File.readAsync(config.root_path + 'constants/sprite_constants.asm')
530580
}
531581

532582
function getMapConstants() {
533583
return getMapConstantsText().then(read_constants)
534584
}
535585

536586
function getMapConstantsText() {
537-
return request(config.map_constants_path)
587+
return File.readAsync(config.map_constants_path)
538588
}
539589

540590
function getMapDimensionsText() {
541-
return request(config.map_dimensions_path)
591+
return File.readAsync(config.map_dimensions_path_prism)
592+
.catch(function () {
593+
return File.readAsync(config.map_dimensions_path)
594+
})
542595
}
543596

544597
function read_constants(text) {
@@ -646,7 +699,7 @@ function addStationaryClickListener(target, callback) {
646699

647700

648701
function getMapGroups () {
649-
return request(config.map_header_path)
702+
return File.readAsync(config.map_header_path)
650703
.then(readMapGroups)
651704
}
652705

@@ -680,7 +733,7 @@ function readMapGroups (text) {
680733
}
681734

682735
function getMapGroupNames () {
683-
return request(config.map_header_path)
736+
return File.readAsync(config.map_header_path)
684737
.then(readMapGroupNames)
685738
}
686739

@@ -695,7 +748,7 @@ function readMapGroupNames (text) {
695748
}
696749

697750
function getMapNames () {
698-
return request(config.map_header_path)
751+
return File.readAsync(config.map_header_path)
699752
.then(readMapNames)
700753
}
701754

@@ -710,7 +763,7 @@ function readMapNames (text) {
710763
}
711764

712765
function getMapHeader(name) {
713-
return request(config.map_header_path)
766+
return File.readAsync(config.map_header_path)
714767
.then( function (text) { return readMapHeader(text, name) } )
715768
}
716769

@@ -750,7 +803,7 @@ function readMapHeader(text, name) {
750803

751804

752805
function getMapHeader2(name) {
753-
return request(config.map_header_2_path)
806+
return File.readAsync(config.map_header_2_path)
754807
.then( function (text) { return readMapHeader2(text, name) } )
755808
}
756809

@@ -859,7 +912,7 @@ function readMapHeader2ByConstant(text, name) {
859912
}
860913

861914
function mapConstantToLabel (constant) {
862-
return request(config.map_header_2_path)
915+
return File.readAsync(config.map_header_2_path)
863916
.then(function (text) {
864917
return readMapHeader2ByConstant(text, constant)
865918
})

js/electron.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Misc code that only applies to Electron.
2+
// For now this is just restoring browser shortcuts.
3+
4+
const _electron = require('electron')
5+
6+
Shortcuts.f12 = function (event) {
7+
_electron.remote.getCurrentWindow().toggleDevTools()
8+
}
9+
10+
Shortcuts.f5 = function (event) {
11+
location.reload()
12+
}
13+
Shortcuts[['ctrl', 'r']] = Shortcuts.f5

0 commit comments

Comments
 (0)