@greenborn/mapa-voxel-back 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ // datos.js - Bindings vivos de los datos de juego que usa el generador.
2
+ //
3
+ // El paquete no trae datos de juego (autos, árboles, tiendas, refugios, etc.):
4
+ // los aporta el consumidor con `registrarPlugins` (ver ./registro.js). Los
5
+ // módulos del generador los importan por nombre desde acá; como son
6
+ // `export let`, al registrar un plugin todos ven el valor nuevo sin
7
+ // volver a importar nada.
8
+ //
9
+ // No leer estos valores al evaluar un módulo (top-level): hasta que se
10
+ // registren valen `null`. Leerlos dentro de funciones.
11
+
12
+ // plugin `arboles`
13
+ export let elegirArbol = null;
14
+
15
+ // plugin `autos`
16
+ export let AUTOS = null;
17
+ export let ORDEN_AUTOS = null;
18
+ export let idEntidadAuto = null;
19
+ export let PROPORCION_MOTOS = null;
20
+
21
+ // plugin `postes`
22
+ export let ID_POSTE = null;
23
+
24
+ // plugin `lucesInteriores`
25
+ export let ID_LUZ_INTERIOR = null;
26
+
27
+ // plugin `refugios`
28
+ export let PROB_REFUGIO_PARCELA = null;
29
+ export let MIN_REFUGIOS = null;
30
+ export let INTENTOS_REFUGIO = null;
31
+ export let REFUGIO = null;
32
+ export let PROFUNDIDAD_REFUGIO = null;
33
+ export let ejesRefugio = null;
34
+ export let rotYHacia = null;
35
+
36
+ // plugin `armarios`
37
+ export let ARMARIO = null;
38
+
39
+ // plugin `necesidades`
40
+ export let sortearArmario = null;
41
+ export let sortearCantidades = null;
42
+
43
+ // plugin `tiendas`
44
+ export let TIENDAS_POR_MAPA = null;
45
+ export let ROT_PUERTA = null;
46
+ export let ALTO_GONDOLA = null;
47
+
48
+ // plugin `hordas` (nidos de zombies y escala de superficie de tiendas)
49
+ export let PROB_NIDO_PARCELA = null;
50
+ export let INTENTOS_NIDO = null;
51
+ export let RADIO_NIDO = null;
52
+ export let DIST_MIN_BASE_NIDO = null;
53
+ export let DIST_MIN_ENTRE_NIDOS = null;
54
+ export let ESCALA_SUPERFICIE = null;
55
+
56
+ // plugin `equipos`
57
+ export let COLORES_EQUIPO = null;
58
+
59
+ // plugin `configuracion`: ajustes generales (p. ej. `lighting.point.distance`)
60
+ export let CONFIG = null;
61
+
62
+ /**
63
+ * Mapa plugin -> nombres de datos que aporta. Es el contrato: cada plugin
64
+ * debe entregar exactamente estos nombres (ver `registrarPlugins`).
65
+ */
66
+ export const ESQUEMA_PLUGINS = Object.freeze({
67
+ arboles: ['elegirArbol'],
68
+ autos: ['AUTOS', 'ORDEN_AUTOS', 'idEntidadAuto', 'PROPORCION_MOTOS'],
69
+ postes: ['ID_POSTE'],
70
+ lucesInteriores: ['ID_LUZ_INTERIOR'],
71
+ refugios: ['PROB_REFUGIO_PARCELA', 'MIN_REFUGIOS', 'INTENTOS_REFUGIO', 'REFUGIO', 'PROFUNDIDAD_REFUGIO', 'ejesRefugio', 'rotYHacia'],
72
+ armarios: ['ARMARIO'],
73
+ necesidades: ['sortearArmario', 'sortearCantidades'],
74
+ tiendas: ['TIENDAS_POR_MAPA', 'ROT_PUERTA', 'ALTO_GONDOLA'],
75
+ hordas: ['PROB_NIDO_PARCELA', 'INTENTOS_NIDO', 'RADIO_NIDO', 'DIST_MIN_BASE_NIDO', 'DIST_MIN_ENTRE_NIDOS', 'ESCALA_SUPERFICIE'],
76
+ equipos: ['COLORES_EQUIPO'],
77
+ configuracion: ['CONFIG'],
78
+ });
79
+
80
+ /** Asigna los nombres de cada plugin a su binding vivo. */
81
+ export function asignarDatos(nombre, valores) {
82
+ switch (nombre) {
83
+ case 'arboles': elegirArbol = valores.elegirArbol; break;
84
+ case 'autos':
85
+ AUTOS = valores.AUTOS; ORDEN_AUTOS = valores.ORDEN_AUTOS;
86
+ idEntidadAuto = valores.idEntidadAuto; PROPORCION_MOTOS = valores.PROPORCION_MOTOS;
87
+ break;
88
+ case 'postes': ID_POSTE = valores.ID_POSTE; break;
89
+ case 'lucesInteriores': ID_LUZ_INTERIOR = valores.ID_LUZ_INTERIOR; break;
90
+ case 'refugios':
91
+ PROB_REFUGIO_PARCELA = valores.PROB_REFUGIO_PARCELA; MIN_REFUGIOS = valores.MIN_REFUGIOS;
92
+ INTENTOS_REFUGIO = valores.INTENTOS_REFUGIO; REFUGIO = valores.REFUGIO;
93
+ PROFUNDIDAD_REFUGIO = valores.PROFUNDIDAD_REFUGIO; ejesRefugio = valores.ejesRefugio;
94
+ rotYHacia = valores.rotYHacia;
95
+ break;
96
+ case 'armarios': ARMARIO = valores.ARMARIO; break;
97
+ case 'necesidades': sortearArmario = valores.sortearArmario; sortearCantidades = valores.sortearCantidades; break;
98
+ case 'tiendas':
99
+ TIENDAS_POR_MAPA = valores.TIENDAS_POR_MAPA; ROT_PUERTA = valores.ROT_PUERTA;
100
+ ALTO_GONDOLA = valores.ALTO_GONDOLA;
101
+ break;
102
+ case 'hordas':
103
+ PROB_NIDO_PARCELA = valores.PROB_NIDO_PARCELA; INTENTOS_NIDO = valores.INTENTOS_NIDO;
104
+ RADIO_NIDO = valores.RADIO_NIDO; DIST_MIN_BASE_NIDO = valores.DIST_MIN_BASE_NIDO;
105
+ DIST_MIN_ENTRE_NIDOS = valores.DIST_MIN_ENTRE_NIDOS; ESCALA_SUPERFICIE = valores.ESCALA_SUPERFICIE;
106
+ break;
107
+ case 'equipos': COLORES_EQUIPO = valores.COLORES_EQUIPO; break;
108
+ case 'configuracion': CONFIG = valores.CONFIG; break;
109
+ default: throw new Error(`plugin desconocido: ${nombre}`);
110
+ }
111
+ }
@@ -0,0 +1,48 @@
1
+ // registro.js - API para que el consumidor registre los plugins de datos.
2
+ //
3
+ // registrarPlugins({
4
+ // arboles: { elegirArbol },
5
+ // autos: { AUTOS, ORDEN_AUTOS, idEntidadAuto, PROPORCION_MOTOS },
6
+ // ... // ver ESQUEMA_PLUGINS en datos.js
7
+ // });
8
+ //
9
+ // Cada plugin es opcional por separado, pero `construirMapa` exige que estén
10
+ // todos (ver `pluginsFaltantes`). Se pueden registrar en varias llamadas: cada
11
+ // una pisa sólo los plugins que trae.
12
+
13
+ import { ESQUEMA_PLUGINS, asignarDatos } from './datos.js';
14
+
15
+ const registrados = new Set();
16
+
17
+ /**
18
+ * Registra uno o más plugins. Lanza `TypeError` si un plugin es desconocido o
19
+ * si le faltan nombres según `ESQUEMA_PLUGINS`.
20
+ */
21
+ export function registrarPlugins(plugins) {
22
+ if (!plugins || typeof plugins !== 'object') {
23
+ throw new TypeError('registrarPlugins: se esperaba un objeto { nombre: datos }');
24
+ }
25
+ for (const nombre of Object.keys(plugins)) {
26
+ const requeridos = ESQUEMA_PLUGINS[nombre];
27
+ if (!requeridos) {
28
+ throw new TypeError(`registrarPlugins: plugin desconocido "${nombre}"`);
29
+ }
30
+ const valores = plugins[nombre] || {};
31
+ const faltan = requeridos.filter(n => valores[n] === undefined);
32
+ if (faltan.length) {
33
+ throw new TypeError(`registrarPlugins: el plugin "${nombre}" no trae: ${faltan.join(', ')}`);
34
+ }
35
+ asignarDatos(nombre, valores);
36
+ registrados.add(nombre);
37
+ }
38
+ }
39
+
40
+ /** Nombres de plugins que todavía no se registraron. Vacío = listo para generar. */
41
+ export function pluginsFaltantes() {
42
+ return Object.keys(ESQUEMA_PLUGINS).filter(n => !registrados.has(n));
43
+ }
44
+
45
+ /** Plugins ya registrados (copia). */
46
+ export function pluginsRegistrados() {
47
+ return [...registrados];
48
+ }