From 3020e3b038b15330f47df09b820c2db170803f65 Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Wed, 10 Mar 2021 22:19:47 -0700 Subject: [PATCH] Count chips in C2Ms on level start, not on parse (so editing updates the chip count) --- js/format-base.js | 4 +++- js/format-c2g.js | 3 --- js/format-dat.js | 1 + js/game.js | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/js/format-base.js b/js/format-base.js index 087b6a3..8068c4c 100644 --- a/js/format-base.js +++ b/js/format-base.js @@ -100,7 +100,9 @@ export class StoredLevel extends LevelInterface { this.author = ''; this.password = null; this.hint = ''; - this.chips_required = 0; + // A number is a specified count; the default of null means that the chips are counted on + // level init, as in CC2 + this.chips_required = null; this.time_limit = 0; this.viewport_size = 9; this.extra_chunks = []; diff --git a/js/format-c2g.js b/js/format-c2g.js index 50c243d..6059b00 100644 --- a/js/format-c2g.js +++ b/js/format-c2g.js @@ -1241,9 +1241,6 @@ export function parse_level(buf, number = 1) { cell[type.layer] = {type}; } - if (type.is_required_chip) { - level.chips_required++; - } if (type.is_hint) { // Remember all the hint tiles (in reading order) so we can map extra hints // to them later. Don't do it now, since the format doesn't technically diff --git a/js/format-dat.js b/js/format-dat.js index 6a0ea81..4ea567e 100644 --- a/js/format-dat.js +++ b/js/format-dat.js @@ -177,6 +177,7 @@ function parse_level(bytes, number) { level.has_custom_connections = true; level.format = 'ccl'; level.uses_ll_extensions = false; + level.chips_required = 0; // Map size is always fixed as 32x32 in CC1 level.size_x = 32; level.size_y = 32; diff --git a/js/game.js b/js/game.js index 8f850bd..755bddb 100644 --- a/js/game.js +++ b/js/game.js @@ -482,7 +482,7 @@ export class Level extends LevelInterface { this.p1_input = 0; this.p1_released = 0xff; this.actors = []; - this.chips_remaining = this.stored_level.chips_required; + this.chips_remaining = this.stored_level.chips_required ?? 0; this.bonus_points = 0; this.aid = 0; @@ -566,6 +566,9 @@ export class Level extends LevelInterface { this.player = tile; } } + if (tile.type.is_required_chip && this.stored_level.chips_required === null) { + this.chips_remaining++; + } if (tile.type.is_actor) { this.actors.push(tile); }