-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreadme-screens.js
More file actions
290 lines (260 loc) · 8.33 KB
/
Copy pathreadme-screens.js
File metadata and controls
290 lines (260 loc) · 8.33 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
'use strict'
/**
* Generate HTML snapshots from the real TUI renderer. Chrome turns these into
* the PNG files embedded by README.md; no hand-written mock screen is involved.
*
* Usage: bare scripts/readme-screens.js <output-directory>
*/
const fs = require('bare-fs')
const path = require('bare-path')
const { Runa } = require('../lib/game.js')
const { Field } = require('../lib/field.js')
const { Dungeon } = require('../lib/dungeon.js')
const { BossZone } = require('../lib/boss-zone.js')
const { BarbarianCamp } = require('../lib/barbarian-camp.js')
const WIDTH = 120
const HEIGHT = 34
const PALETTE = {
30: '#111827',
31: '#ff6b6b',
32: '#73d99a',
33: '#f2c94c',
34: '#61afef',
35: '#c678dd',
36: '#56d4dd',
37: '#d8dee9',
90: '#6b7280',
91: '#ff8585',
92: '#8ee6aa',
93: '#ffd76a',
94: '#80bfff',
95: '#dd93ef',
96: '#75e7ed',
97: '#ffffff'
}
function escapeHtml(value) {
return String(value)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
}
function ansiToHtml(value) {
const source = String(value)
const pattern = /\x1b\[([0-9;]*)m/g
const state = { color: '', bold: false, dim: false, reverse: false }
let cursor = 0
let output = ''
const open = () => {
const css = []
if (state.color) css.push(`color:${state.color}`)
if (state.bold) css.push('font-weight:700')
if (state.dim) css.push('opacity:.58')
if (state.reverse) css.push('color:#11151d;background:#d8dee9')
return css.length ? `<span style="${css.join(';')}">` : '<span>'
}
while (true) {
const match = pattern.exec(source)
if (!match) break
output += open() + escapeHtml(source.slice(cursor, match.index)) + '</span>'
const codes = (match[1] || '0').split(';').map((code) => Number(code || 0))
for (const code of codes) {
if (code === 0) Object.assign(state, { color: '', bold: false, dim: false, reverse: false })
else if (code === 1) state.bold = true
else if (code === 2) state.dim = true
else if (code === 7) state.reverse = true
else if (code === 22) Object.assign(state, { bold: false, dim: false })
else if (code === 27) state.reverse = false
else if (code === 39) state.color = ''
else if (PALETTE[code]) state.color = PALETTE[code]
}
cursor = pattern.lastIndex
}
return output + open() + escapeHtml(source.slice(cursor)) + '</span>'
}
function page(title, frame) {
return `<!doctype html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>${escapeHtml(title)}</title>
<style>
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
display: grid;
place-items: center;
background: radial-gradient(circle at 50% 0%, #263043 0, #11151d 58%, #090c12 100%);
}
.terminal {
overflow: hidden;
border: 1px solid #343b49;
border-radius: 16px;
background: #11151d;
box-shadow: 0 28px 80px rgba(0,0,0,.52), 0 0 0 1px rgba(255,255,255,.025) inset;
}
.bar {
height: 42px;
display: flex;
align-items: center;
gap: 9px;
padding: 0 17px;
background: #1d222c;
border-bottom: 1px solid #2e3542;
}
.dot { width: 11px; height: 11px; border-radius: 50%; }
.red { background: #ff5f57; }
.yellow { background: #febc2e; }
.green { background: #28c840; }
.caption {
margin-left: 9px;
color: #7c8597;
font: 12px/1 "Segoe UI", sans-serif;
letter-spacing: .08em;
text-transform: uppercase;
}
pre {
margin: 0;
padding: 22px 26px 25px;
color: #d8dee9;
background: #11151d;
font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
font-size: 13px;
line-height: 1.16;
font-variant-ligatures: none;
white-space: pre;
}
</style>
</head>
<body>
<div class="terminal">
<div class="bar">
<span class="dot red"></span><span class="dot yellow"></span><span class="dot green"></span>
<span class="caption">Runa · ${escapeHtml(title)}</span>
</div>
<pre>${ansiToHtml(frame)}</pre>
</div>
</body>
</html>`
}
function key(name) {
return { type: 'key', is: (...keys) => keys.includes(name) }
}
function type(sequence) {
return { type: 'key', sequence, ctrl: false, meta: false, is: () => false }
}
function namedGame(name = 'Ayla', realm = 'runa') {
const game = new Runa({ presence: false })
game.width = WIDTH
game.height = HEIGHT
game.onKey(key('enter'))
for (const ch of name) game.onKey(type(ch))
if (realm === 'nox') game.onKey(key('right'))
game.onKey(key('enter'))
return game
}
function equippedGame(name = 'Ayla') {
const game = namedGame(name)
for (const id of ['spear', 'shield', 'chainmail', 'iron_helmet', 'boots', 'longbow']) {
game.player.items.add(id)
}
for (const id of ['spear', 'shield', 'chainmail', 'iron_helmet', 'boots']) {
game.player.equip(id)
}
return game
}
function frames() {
const menu = new Runa({ presence: false })
menu.width = WIDTH
menu.height = HEIGHT
const name = new Runa({ presence: false })
name.width = WIDTH
name.height = HEIGHT
name.onKey(key('enter'))
for (const ch of 'Ayla') name.onKey(type(ch))
const city = equippedGame()
city.walker.placeAt('city', 160, 102)
const field = equippedGame()
field.field = new Field({ seed: 17, player: field.player })
field.field.player.x = 111
field.field.player.y = 10
const clearedField = equippedGame()
clearedField.field = new Field({
seed: 17,
player: clearedField.player,
clearedSettlements: ['colmillo-rojo']
})
clearedField.field.player.x = 111
clearedField.field.player.y = 10
const barbarians = equippedGame()
barbarians.field = new BarbarianCamp({
campId: 'hachas-negras',
seed: 17,
player: barbarians.player
})
barbarians.field.player.x = 54
barbarians.field.player.y = 20
const combat = equippedGame()
combat.field = new Field({ seed: 17, player: combat.player })
const foe = combat.field.foes.find((candidate) => !candidate.dead)
combat.field.player.x = foe.x > 1 ? foe.x - 2 : foe.x + 2
combat.field.player.y = foe.y
combat.onKey(key(foe.x > combat.field.player.x ? 'right' : 'left'))
combat.onKey(key('f'))
const equipment = equippedGame()
equipment.shop = 'armor'
equipment.cursor = 0
const nox = namedGame('Nyra', 'nox')
nox.animationTick = 12
nox.walker.placeAt('nox', 160, 103)
const noxPalace = namedGame('Nyra', 'nox')
noxPalace.animationTick = 12
noxPalace.walker.placeAt('nox', 160, 10)
const noxWorkshops = namedGame('Nyra', 'nox')
noxWorkshops.animationTick = 12
noxWorkshops.walker.placeAt('nox', 42, 148)
const dungeon = equippedGame('Ayla')
dungeon.field = new Dungeon({
floor: 2,
seed: 31,
player: dungeon.player,
script: dungeon.scriptSource,
x: 57,
y: 20
})
const worldBoss = equippedGame('Ayla')
worldBoss.field = new BossZone({
seed: 27,
player: worldBoss.player,
script: worldBoss.scriptSource,
x: 101,
y: 22
})
worldBoss.animationTick = 9
const inventory = equippedGame('Ayla')
inventory.openInventory()
return {
menu: { title: 'menu principal', frame: menu.view() },
nombre: { title: 'nueva partida', frame: name.view() },
ciudad: { title: 'ciudad', frame: city.view() },
campo: { title: 'pradera', frame: field.view() },
'campo-limpio': { title: 'pradera conquistada', frame: clearedField.view() },
barbaros: { title: 'asentamiento barbaro', frame: barbarians.view() },
combate: { title: 'combate en el mapa', frame: combat.view() },
equipo: { title: 'armaduras y equipo', frame: equipment.view() },
nox: { title: 'reino elfico oscuro de nox', frame: nox.view() },
'nox-palacio': { title: 'palacio del eclipse', frame: noxPalace.view() },
'nox-oficios': { title: 'barrio de oficios de nox', frame: noxWorkshops.view() },
dungeon: { title: 'cripta - nivel 2', frame: dungeon.view() },
'world-boss': { title: 'ruinas volcanicas del coloso', frame: worldBoss.view() },
inventario: { title: 'inventario y equipo', frame: inventory.view() }
}
}
const output = path.resolve(Bare.argv[2] || '.readme-screens')
fs.mkdirSync(output, { recursive: true })
for (const [name, screen] of Object.entries(frames())) {
const target = path.join(output, name + '.html')
fs.writeFileSync(target, page(screen.title, screen.frame))
console.log(target)
}