From 214a430e52c44e24a5078a1d672ae627023e6f30 Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Tue, 8 Sep 2020 14:11:20 -0600 Subject: [PATCH] Load the CC2 thin walls (and canopy) --- js/format-c2m.js | 38 ++++++++++++++++++++++++++++++++------ js/format-util.js | 3 --- js/tiletypes.js | 4 ++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/js/format-c2m.js b/js/format-c2m.js index 68e3d90..820ac84 100644 --- a/js/format-c2m.js +++ b/js/format-c2m.js @@ -171,7 +171,7 @@ const TILE_ENCODING = { // 0x6a: Time penalty : '#next' // 0x6b: Custom floor (green) : Modifier allows other styles, see below // 0x6c: (Unused) : - // 0x6d: Thin wall / Canopy : Panel/Canopy bitmask (see below), '#next' + 0x6d: ['#thinwall/canopy', '#next'], // 0x6e: (Unused) : // 0x6f: Railroad sign : '#next' // 0x70: Custom wall (green) : Modifier allows other styles, see below @@ -401,6 +401,7 @@ export function parse_level(buf) { let [name, ...args] = read_spec(); if (name === undefined) continue; // XXX modifier skip hack + // Deal with modifiers let modifier; if (name === '#mod8') { if (args[0] !== '#next') @@ -414,6 +415,36 @@ export function parse_level(buf) { throw new Error(`Expected a tile requiring a modifier`); } + // Make a tile template, possibly dealing with some special cases + if (name === '#thinwall/canopy') { + // Thin walls and the canopy are combined into a single + // byte for some reason; split them apart here. Which + // ones we get is determined by a bitmask + let mask = bytes[p]; + p++; + // This order is important; this is the order CC2 draws them in + if (mask & 0x10) { + cell.push({name: 'canopy'}); + } + if (mask & 0x08) { + cell.push({name: 'thinwall_w'}); + } + if (mask & 0x04) { + cell.push({name: 'thinwall_s'}); + } + if (mask & 0x02) { + cell.push({name: 'thinwall_e'}); + } + if (mask & 0x01) { + cell.push({name: 'thinwall_n'}); + } + // Skip the rest of the loop. That means we don't + // handle any of the other special behavior below, but + // neither thin walls nor canopies should use any of + // it, so that's fine + continue; + } + let tile = {name, modifier}; cell.push(tile); let type = TILE_TYPES[name]; @@ -421,11 +452,6 @@ export function parse_level(buf) { if (type.is_required_chip) { level.chips_required++; } - if (type.is_player) { - // TODO handle multiple starts - level.player_start_x = n % width; - level.player_start_y = Math.floor(n / width); - } 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, diff --git a/js/format-util.js b/js/format-util.js index cc0fe70..740f860 100644 --- a/js/format-util.js +++ b/js/format-util.js @@ -20,9 +20,6 @@ export class StoredLevel { this.size_y = 0; this.linear_cells = []; - this.player_start_x = 0; - this.player_start_y = 0; - // Maps of button positions to trap/cloner positions, as scalar indexes // in the linear cell list this.custom_trap_wiring = {}; diff --git a/js/tiletypes.js b/js/tiletypes.js index 0500046..c374850 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -5,6 +5,7 @@ const LAYER_TERRAIN = 0; const LAYER_ITEM = 1; const LAYER_ACTOR = 2; const LAYER_OVERLAY = 3; +// TODO cc2 order is: swivel, thinwalls, canopy (and yes you can have them all in the same tile) const TILE_TYPES = { // Floors and walls @@ -76,6 +77,9 @@ const TILE_TYPES = { level.transmute_tile(me, 'floor'); }, }, + canopy: { + draw_layer: LAYER_OVERLAY, + }, // Swivel doors swivel_floor: {