clone

a browser grid puzzle game where you push words around to rewrite the rules of each level

feat: normalize pack rules compatibility revisions

Dami committed 9d1d263
commit
9d1d263e4156c77401114c863d78be382de30611
parent
a9392796260aac77a1e871ec1a77bbd6d76e9faf
author
Dami <dami.etoile@gmail.com>
6 files changed, +33 -5
Msrc/catalog.js5+++--
Msrc/mods.js7+++++++
Msrc/mods/diagnostics.js14++++++++++++++
Msrc/pack-service.js2++
Msrc/scenes/map.js2+-
Msrc/share.js8++++++--
M src/catalog.js +3 -2
M src/mods.js +7 -0
@@ -11,6 +11,8 @@ export { collectModWarnings, MAX_MOD_WARNINGS } from './mods/diagnostics.js';
1111 */1212 1313 export const MOD_SCHEMA_VERSION = 1;14+export const CURRENT_RULES_VERSION = 2;15+export const LEGACY_RULES_VERSION = 1;1416 export const MAX_MOD_SOURCE_LENGTH = 512 * 1024;1517 export const MAX_MOD_LEVELS = 64;1618 export const MAX_LEVEL_OBJECTS = 4096;
@@ -217,6 +219,10 @@ export function validateMod(mod) {
217219 if (manifest.forkOf !== undefined && (typeof manifest.forkOf !== 'string' || !ID_RE.test(manifest.forkOf))) errors.push(issue('manifest.forkOf', 'must be the original pack id'));218220 if (typeof manifest.version !== 'string' || !VERSION_RE.test(manifest.version)) errors.push(issue('manifest.version', 'must be a semantic version such as 1.0.0'));219221 if (manifest.engine !== undefined && manifest.engine !== MOD_SCHEMA_VERSION) errors.push(issue('manifest.engine', `must be ${MOD_SCHEMA_VERSION} for this loader`));222+ if (manifest.rules !== undefined) {223+ if (!isInteger(manifest.rules) || manifest.rules < 1) errors.push(issue('manifest.rules', 'must be a positive integer no greater than 2'));224+ else if (manifest.rules > CURRENT_RULES_VERSION) errors.push(issue('manifest.rules', `unsupported future rules revision ${manifest.rules}; host supports ${CURRENT_RULES_VERSION}`));225+ }220226 }221227 if (manifest && manifest.features !== undefined) {222228 if (!Array.isArray(manifest.features)) errors.push(issue('manifest.features', 'must be an array of unique lowercase feature identifiers'));
@@ -257,6 +263,7 @@ export function validateMod(mod) {
257263 function normalizeMod(mod) {258264 const normalized = copy(mod);259265 normalized.manifest.engine = normalized.manifest.engine ?? MOD_SCHEMA_VERSION;266+ normalized.manifest.rules = normalized.manifest.rules ?? LEGACY_RULES_VERSION;260267 normalized.levels = normalized.levels.map(level => ({261268 ...level,262269 ...(Array.isArray(level.automata) ? { automata: level.automata.map(automaton => ({
M src/mods/diagnostics.js +14 -0
M src/pack-service.js +2 -0
M src/scenes/map.js +1 -1
M src/share.js +6 -2