diff --git a/Input.js b/Input.js index 5e028fd..3aef31f 100644 --- a/Input.js +++ b/Input.js @@ -52,12 +52,13 @@ const showAutoXpSynonyms = ["showautoxp"] const setDefaultDifficultySynonyms = ["setdefaultdifficulty", "defaultdifficulty", "setdefaultdc", "defaultdc", "setdefaultac", "defaultac", "setdifficulty", "difficulty", "dc"] const showDefaultDifficultySynonyms = ["showdefaultdifficulty", "showdefaultdc", "showdefaultac"] const generateNameSynonyms = ["generatename", "name", "randomname", "makename", "createname"] -const createLocationSynonyms = ["createlocation", "makelocation", "generatelocation", "addlocation", "createplace", "makeplace", "generateplace", "addplace", "createtown", "maketown", "generatetown", "addtown", "createvillage", "makevillage", "generatevillage", "addvillage", "createcity", "makecity", "generatecity", "addcity", "updatelocation", "updateplace", "updatetown", "updatevillage", "updatecity"] +const createLocationSynonyms = ["createlocation", "makelocation", "generatelocation", "addlocation", "setlocation", "createplace", "makeplace", "generateplace", "addplace", "setplace", "createtown", "maketown", "generatetown", "addtown", "settown", "createvillage", "makevillage", "generatevillage", "addvillage", "setvillage", "createcity", "makecity", "generatecity", "addcity", "setcity", "updatelocation", "updateplace", "updatetown", "updatevillage", "updatecity"] const goToLocationSynonyms = ["gotolocation", "golocation", "movetolocation", "traveltolocation", "travellocation", "gotoplace", "goplace", "movetoplace", "traveltoplace", "travelplace", "gototown", "gotown", "movetotown", "traveltotown", "traveltown", "gotovillage", "govillage", "movetovillage", "traveltovillage", "travelvillage", "gotocity", "gocity", "movetocity", "traveltocity", "travelcity", "goto", "go", "moveto", "move", "travelto", "travel"] const removeLocationSynonyms = ["removelocation", "deletelocation", "eraselocation", "removeplace", "deleteplace", "eraseplace", "removetown", "deletetown", "erasetown", "removevillage", "deletevillage", "erasevillage", "removecity", "deletecity", "erasecity"] const showLocationsSynonyms = ["showlocations", "showplaces", "showtowns", "showvillages", "showcities", "locations", "places", "towns", "villages", "cities"] const getLocationSynonyms = ["getlocation", "location", "getcoordinates", "coordinates", "getcoords", "coords", "showlocation"] const clearLocationsSynonyms = ["clearlocations", "eraselocations", "deletelocations", "resetlocations"] +const mapSynonyms = ["map", "showmap"] const helpSynonyms = ["help"] const modifier = (text) => { @@ -162,6 +163,7 @@ const modifier = (text) => { if (text == null) text = processCommandSynonyms(command, commandName, removeLocationSynonyms, doRemoveLocation) if (text == null) text = processCommandSynonyms(command, commandName, showLocationsSynonyms, doShowLocations) if (text == null) text = processCommandSynonyms(command, commandName, getLocationSynonyms, doGetLocation) + if (text == null) text = processCommandSynonyms(command, commandName, mapSynonyms, doMap) if (text == null) text = processCommandSynonyms(command, commandName, renameCharacterSynonyms, doRenameCharacter) if (text == null) text = processCommandSynonyms(command, commandName, cloneCharacterSynonyms, doCloneCharacter) if (text == null) text = processCommandSynonyms(command, commandName, helpSynonyms, doHelp) @@ -1246,8 +1248,8 @@ function doGoToLocation(command) { if (location == null) { distance = pointDistance(state.x, state.y, arg0, arg1) - state.x = arg0 - state.y = arg1 + state.x = parseInt(arg0) + state.y = parseInt(arg1) } else { distance = pointDistance(state.x, state.y, location.x, location.y) state.x = location.x @@ -1373,6 +1375,11 @@ function doTake(command) { return text } +function doMap(command) { + state.show = "map" + return " " +} + function doDrop(command) { var character = getCharacter() var commandName = getCommandName(command) diff --git a/Library.js b/Library.js index fe13303..54e9817 100644 --- a/Library.js +++ b/Library.js @@ -31,6 +31,7 @@ function rotate(cx, cy, x, y, angle) { } function createLocation(x, y, name) { + log(`createlocation ${name}:${x},${y}`) if (x == null || y == null) { var cx = x == null ? state.x : x var cy = y == null ? state.y : y @@ -340,6 +341,10 @@ function findSpellCardIndex(name) { return storyCards.findIndex((element) => element.type == "spell" && element.keys == name) } +String.prototype.replaceAt = function(index, replacement) { + return this.substring(0, index) + replacement + this.substring(index + replacement.length); +} + String.prototype.plural = function(revert) { var plural = { diff --git a/Output.js b/Output.js index 2aa9166..1b6d218 100644 --- a/Output.js +++ b/Output.js @@ -187,6 +187,15 @@ const modifier = (text) => { } text += "******************\n\n" break + case "map": + text += `A 11x11 map of the area surrounding (${state.x},${state.y}):\n` + var map = mapGenerate() + map = mapReplace(map, state.x, state.y, "@") + state.locations.forEach(location => { + map = mapReplace(map, location.x, location.y, location.name.substring(0, 1).toUpperCase()) + }) + text += map + break case "none": text += " " break @@ -348,4 +357,27 @@ const modifier = (text) => { return { text } } +const mapLineBreak = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" +const mapLine = "| * * * * * * * * * * * |\n" + +function mapGenerate() { + var map = mapLineBreak + for (var i = 0; i < 11; i++) map += mapLine + map += mapLineBreak + return map +} + +function mapReplace(map, x, y, character) { + x += 5 - state.x + y += 5 - state.y + + if (x < 0 || x > 10 || y < 0 || y > 10) return map + + index = mapLineBreak.length + 6 + x * 6 + y * mapLine.length + + map = map.replaceAt(index, character) + + return map +} + modifier(text) \ No newline at end of file diff --git a/README.md b/README.md index 097e7eb..3d53850 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ See the [user guide here](https://github.com/raeleus/Hashtag-DnD/wiki). v. 0.1.0 * Added `#createlocation`, `#goto`, `#removelocation`, `#clearlocations`, `#getlocation` and `#showlocations` to enable travelling. +* Added `#map` to generate an ASCII map based on the locations and player location. * Added `#renameitem` to rename an existing item * Added `#renamecharacter` to rename an existing character * Added `#clonecharacter` to copy an existing character