-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug-map.ts
132 lines (100 loc) · 3.77 KB
/
debug-map.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const Jimp = require( 'jimp' )
import { mapSize, tileSize } from './settings'
import { createIsland, observableCreateIsland } from './map'
import {
MAP_TILES, T_GRASS, T_GRASS_L, T_TREE, T_TREE_L, MAP_PLAYERX, MAP_PLAYERY,
T_SAND, T_SAND_L, T_HUT, T_MOUNTAINS, T_MOUNTAINS_L, T_RUINS, T_RUINS_L,
T_LAND, T_RANGER, T_SATELLITE, T_PORTAL
} from './indices'
import { DisplayMap } from './types';
const start = process.hrtime()
const mapData = createIsland([[]],[[]],[[]])
const end = process.hrtime( start )
console.log( `time: ${ end[ 0 ] }s ${ end[ 1] / 1000000 }ms` )
const map = mapData[ MAP_TILES ]
const playerX = mapData[ MAP_PLAYERX ]
const playerY = mapData[ MAP_PLAYERY ]
const createColorMap = ( map: number[][], name: string, playerX?: number, playerY?: number ) => {
new Jimp( mapSize, mapSize, ( err, image ) => {
if ( err ) {
throw err
}
for ( let y = 0; y < mapSize; y++ ) {
for ( let x = 0; x < mapSize; x++ ) {
let color = Jimp.rgbaToInt( 255, 0, 255, 255 )
if ( map[ y ][ x ] === 0 ) {
color = Jimp.rgbaToInt( 0, 0, 255, 255 )
}
if ( map[ y ][ x ] === 1 ) {
color = Jimp.rgbaToInt( 0, 0, 0, 255 )
}
if ( map[ y ][ x ] === T_LAND ) {
color = Jimp.rgbaToInt( 96, 255, 96, 255 )
}
if ( map[ y ][ x ] >= T_GRASS && map[ y ][ x ] < T_GRASS + T_GRASS_L ) {
color = Jimp.rgbaToInt( 32, 192, 96, 255 )
}
if ( map[ y ][ x ] >= T_TREE && map[ y ][x ] < T_TREE + T_TREE_L ) {
color = Jimp.rgbaToInt( 0, 128, 0, 255 )
}
if ( map[ y ][ x ] >= T_SAND && map[ y ][ x ] < T_SAND + T_SAND_L ) {
color = Jimp.rgbaToInt( 255, 255, 0, 255 )
}
if ( map[ y ][ x ] >= T_MOUNTAINS && map[ y ][ x ] < T_MOUNTAINS + T_MOUNTAINS_L ) {
color = Jimp.rgbaToInt( 128, 64, 0, 255 )
}
if ( map[ y ][ x ] >= T_RUINS && map[ y ][ x ] < T_RUINS + T_RUINS_L ) {
color = Jimp.rgbaToInt( 192, 192, 192, 255 )
}
if ( map[ y ][ x ] >= T_SAND && map[ y ][ x ] < T_SAND + T_SAND_L ) {
color = Jimp.rgbaToInt( 192, 192, 0, 255 )
}
if ( map[ y ][ x ] === T_HUT ) {
color = Jimp.rgbaToInt( 255, 255, 255, 255 )
}
if ( map[ y ][ x ] === T_RANGER ) {
color = Jimp.rgbaToInt( 255, 128, 0, 255 )
}
if ( map[ y ][ x ] === T_SATELLITE ) {
color = Jimp.rgbaToInt( 0, 255, 255, 255 )
}
if ( map[ y ][ x ] === T_PORTAL ) {
color = Jimp.rgbaToInt( 128, 0, 255, 255 )
}
if ( x === playerX && y === playerY ) {
color = Jimp.rgbaToInt( 255, 0, 0, 255 )
}
image.setPixelColor( color, x, y )
}
}
image.write( `./debug/${ name }.png` )
} )
}
createColorMap( map, 'island', playerX, playerY )
observableCreateIsland( createColorMap )
// async image loader
const loadImage = ( path: string ) => Jimp.read( path )
// load a series of images
const loadImages = ( ...paths: string[] ) => Promise.all( paths.map( loadImage ) )
loadImages( './dist/f.gif', './dist/t.gif', './dist/p.gif', './dist/s.png', './dist/c.gif' ).then( imgs => {
const [ font, tiles, player, splash, computerIcons ] = imgs
const map = mapData[ MAP_TILES ]
// big map
new Jimp( mapSize * tileSize, mapSize * tileSize, ( err, image ) => {
if ( err ) {
throw err
}
for( let mapY = 0; mapY < mapSize; mapY++ ){
for( let mapX = 0; mapX < mapSize; mapX++ ){
const tileIndex = map[ mapY ][ mapX ]
image.blit(
tiles,
mapX * tileSize, mapY * tileSize,
tileIndex * tileSize, 0,
tileSize, tileSize
)
}
}
image.write( './debug/map.png' )
})
} )