From 25c0e53696c38c64acaa4c75b0e2043fd16d35f2 Mon Sep 17 00:00:00 2001 From: synth-ruiner Date: Tue, 8 May 2018 21:30:26 +0100 Subject: [PATCH] better room ID handling (needs testing) --- includes/script.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/script.js b/includes/script.js index 809a6bd..07ca460 100644 --- a/includes/script.js +++ b/includes/script.js @@ -495,9 +495,13 @@ $(document).ready(function() { // handle rooms // need to import IDs so we don't give the new room a conflicting ID - var roomNames = newGameData.match(/ROOM \d+/g); + var roomIds = newGameData.match(/ROOM \d+\n/g); - var newRoomId = parseInt(_.last(roomNames).replace(/[^\d]+/g, "")) + 1; + roomIds = _.map(roomIds, function(roomId) { + return parseInt(roomId.replace(/[^\d]+/g, "")); + }); + + var newRoomId = _.max(roomIds) + 1; var newRoomName = $('#roomName').val(); // remove invalid chars? what's invalid? newlines? are those possible?