From 92fc206423b4dfbf1b585fa082b1a2d4e8fb360f Mon Sep 17 00:00:00 2001 From: raeleus Date: Mon, 30 Sep 2024 09:21:16 -0700 Subject: [PATCH] Added #gonorth, #gosouth, #goeast, #gowest. Resolves #27 --- Input.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- Output.js | 12 ++++++++-- README.md | 2 +- 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/Input.js b/Input.js index 3aef31f..7830215 100644 --- a/Input.js +++ b/Input.js @@ -59,6 +59,10 @@ const showLocationsSynonyms = ["showlocations", "showplaces", "showtowns", "show const getLocationSynonyms = ["getlocation", "location", "getcoordinates", "coordinates", "getcoords", "coords", "showlocation"] const clearLocationsSynonyms = ["clearlocations", "eraselocations", "deletelocations", "resetlocations"] const mapSynonyms = ["map", "showmap"] +const goNorthSynonyms = ["gonorth", "north", "goup", "up", "n"] +const goSouthSynonyms = ["gosouth", "south", "godown", "down", "s"] +const goEastSynonyms = ["goeast", "east", "goright", "right", "e"] +const goWestSynonyms = ["gowest", "west", "goleft", "left", "w"] const helpSynonyms = ["help"] const modifier = (text) => { @@ -91,7 +95,7 @@ const modifier = (text) => { return { text } } - if (!found) found = processCommandSynonyms(command, commandName, helpSynonyms.concat(rollSynonyms, noteSynonyms, eraseNoteSynonyms, showNotesSynonyms, clearNotesSynonyms, showCharactersSynonyms, removeCharacterSynonyms, generateNameSynonyms, setDefaultDifficultySynonyms, showDefaultDifficultySynonyms, renameCharacterSynonyms, cloneCharacterSynonyms, createLocationSynonyms, showLocationsSynonyms, goToLocationSynonyms, removeLocationSynonyms, getLocationSynonyms, clearLocationsSynonyms, resetSynonyms), function () {return true}) + if (!found) found = processCommandSynonyms(command, commandName, helpSynonyms.concat(rollSynonyms, noteSynonyms, eraseNoteSynonyms, showNotesSynonyms, clearNotesSynonyms, showCharactersSynonyms, removeCharacterSynonyms, generateNameSynonyms, setDefaultDifficultySynonyms, showDefaultDifficultySynonyms, renameCharacterSynonyms, cloneCharacterSynonyms, createLocationSynonyms, showLocationsSynonyms, goToLocationSynonyms, removeLocationSynonyms, getLocationSynonyms, clearLocationsSynonyms, goNorthSynonyms, goSouthSynonyms, goEastSynonyms, goWestSynonyms, resetSynonyms), function () {return true}) if (found == null) { if (state.characterName == null) { @@ -164,6 +168,10 @@ const modifier = (text) => { 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, goNorthSynonyms, doGoNorth) + if (text == null) text = processCommandSynonyms(command, commandName, goSouthSynonyms, doGoSouth) + if (text == null) text = processCommandSynonyms(command, commandName, goEastSynonyms, doGoEast) + if (text == null) text = processCommandSynonyms(command, commandName, goWestSynonyms, doGoWest) 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) @@ -1208,6 +1216,62 @@ function doCreateLocation(command) { return `\n[Location ${toTitleCase(arg2)} has been created at (${location.x},${location.y})]\n` } +function doGoNorth(command) { + var commandName = getCommandName(command) + var arg0 = getArgument(command, 0) + if (arg0 == null) arg0 = 1 + else { + if (isNaN(arg0)) { + state.show = none + return "\n[Error: Expected a number. See #help]\n" + } + arg0 = parseInt(arg0) + } + return doGoToLocation(`${commandName} ${state.x} ${state.y - arg0}`) +} + +function doGoSouth(command) { + var commandName = getCommandName(command) + var arg0 = getArgument(command, 0) + if (arg0 == null) arg0 = 1 + else { + if (isNaN(arg0)) { + state.show = none + return "\n[Error: Expected a number. See #help]\n" + } + arg0 = parseInt(arg0) + } + return doGoToLocation(`${commandName} ${state.x} ${state.y + arg0}`) +} + +function doGoEast(command) { + var commandName = getCommandName(command) + var arg0 = getArgument(command, 0) + if (arg0 == null) arg0 = 1 + else { + if (isNaN(arg0)) { + state.show = none + return "\n[Error: Expected a number. See #help]\n" + } + arg0 = parseInt(arg0) + } + return doGoToLocation(`${commandName} ${state.x + arg0} ${state.y}`) +} + +function doGoWest(command) { + var commandName = getCommandName(command) + var arg0 = getArgument(command, 0) + if (arg0 == null) arg0 = 1 + else { + if (isNaN(arg0)) { + state.show = none + return "\n[Error: Expected a number. See #help]\n" + } + arg0 = parseInt(arg0) + } + return doGoToLocation(`${commandName} ${state.x - arg0} ${state.y}`) +} + function doGoToLocation(command) { var character = getCharacter() var characterName = character == null ? "You" : character.name diff --git a/Output.js b/Output.js index ef301af..1c97b17 100644 --- a/Output.js +++ b/Output.js @@ -330,9 +330,17 @@ const modifier = (text) => { text += "\n\n--Locations--" text += "\n#createlocation (x) (y) location_name" - text += "\n Creates a location at the given coordinates. If the coordinates are not provided, they are randomized within a range of 10 units from the player's current location. Multiple locations may exist at the same coordinates. A story card is created for the location. Quotes are not necessary." + text += "\n Creates a location at the given coordinates. The coordinates must be integers. If the coordinates are not provided, they are randomized within a range of 10 units from the player's current location. Multiple locations may exist at the same coordinates. A story card is created for the location. Quotes are not necessary." text += "\n#goto (x) (y) or (location_name)" - text += "\n Makes the characters travel to the location specified by the coordinates or location_name. You must provide at least one or the other. If the location does not exist, it is created at your current coordinates. If you only specify coordinates, you will go to the first location at those coordinates. Quotes are not necessary." + text += "\n Makes the party travel to the location specified by the coordinates (as integers) or location_name. You must provide at least one or the other. If the location does not exist, it is created at your current coordinates. If you only specify coordinates, you will go to the first location at those coordinates. Quotes are not necessary." + text += "\n#gonorth (distance)" + text += "\n The party travels north the given distance (an integer). If distance is not specified, it is assumed to be 1." + text += "\n#gosouth (distance)" + text += "\n The party travels south the given distance (an integer). If distance is not specified, it is assumed to be 1." + text += "\n#goeast (distance)" + text += "\n The party travels east the given distance (an integer). If distance is not specified, it is assumed to be 1." + text += "\n#gowest (distance)" + text += "\n The party travels west the given distance (an integer). If distance is not specified, it is assumed to be 1." text += "\n#getlocation" text += "\n Returns the coordinates that the player's party is at. It will also list a location if a location was specified when using #goto." text += "\n#showlocations" diff --git a/README.md b/README.md index 3d53850..c8e058b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Personalized note system that does not take up context space
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 `#createlocation`, `#goto`, `#gonorth`, `#gosouth`, `#goeast`, `#gowest`, `#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