From 6dd06d2b89125877a1265d9a59efd8fb411decb5 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Sun, 20 Mar 2016 20:46:40 +0700 Subject: [PATCH] Resolves #20 - proper inventory, list of carried things --- game/begin.coffee | 19 +++++++++++++++++++ html/index.html | 27 +++++++++++++-------------- lib/character.coffee | 13 +++++++++++++ lib/obj.coffee | 2 +- lib/room.coffee | 4 +++- lib/salet.coffee | 11 +++++++++-- lib/view.coffee | 2 +- sass/main.scss | 19 +++++++------------ 8 files changed, 66 insertions(+), 31 deletions(-) diff --git a/game/begin.coffee b/game/begin.coffee index 950b61c..a9327b9 100644 --- a/game/begin.coffee +++ b/game/begin.coffee @@ -34,3 +34,22 @@ room "start", salet, dsc: """ """, choices: "#start" + +# This is a special inventory room. +# The inventory button is a regular link to this room. +# You may alter these as much as you like or scrap it along with the button. +room "inventory", salet, + enter: () -> + $("#inventory").hide() + exit: () -> + $("#inventory").show() + dsc: (salet) -> + if salet.character.inventory.length == 0 + text = "You are carrying nothing." + else + text = "You are carrying:\n\n" + for thing in salet.character.inventory + text += "* #{salet.character.listinv(thing.name)}\n" + return text+"\n\n"+""" +
+ """ diff --git a/html/index.html b/html/index.html index db994e4..904fec6 100644 --- a/html/index.html +++ b/html/index.html @@ -58,20 +58,19 @@ -
- diff --git a/lib/character.coffee b/lib/character.coffee index e8cf7e5..0371d9e 100644 --- a/lib/character.coffee +++ b/lib/character.coffee @@ -1,3 +1,6 @@ +invlink = (content, ref) -> + return "#{content}" + class Character constructor: (spec) -> @inventory = [] @@ -16,6 +19,16 @@ class Character return true return false + @listinv = (thing) => + for i in @inventory + if i.name == thing + return invlink(i.name, i.name) + + @inv = (thing) => + for i in @inventory + if i.name == thing + return i.inv.fcall(i) + for index, value of spec this[index] = value return this diff --git a/lib/obj.coffee b/lib/obj.coffee index 3aeb73e..c75e815 100644 --- a/lib/obj.coffee +++ b/lib/obj.coffee @@ -32,7 +32,7 @@ class SaletObj @take = (system) => "You take the #{@name}." # taking to inventory @act = (system) => "You don't find anything extraordinary about the #{@name}." # object action @dsc = (system) => "You see a {{#{@name}}} here." # object description - @inv = (system) => "It's a {{#{@name}.}}" # inventory description + @inv = (system) => "It's a #{@name}." # inventory description @location = "" @put = (salet, location) => @level = 0 # this is scenery diff --git a/lib/room.coffee b/lib/room.coffee index ca7091b..6b8c020 100644 --- a/lib/room.coffee +++ b/lib/room.coffee @@ -155,7 +155,9 @@ class SaletRoom You could interpret this as an EXAMINE verb or USE one, it's your call. ### @act = (system, action) => - if (link = action.match(/^_(act|cycle)_(.+)$/)) #object action + if (link = action.match(/^_(act|cycle|inv)_(.+)$/)) #object action + if link[1] == "inv" + return system.view.write system.character.inv(link[2]) for thing in @objects if thing.name == link[2] if link[1] == "act" diff --git a/lib/salet.coffee b/lib/salet.coffee index 70c9fa1..5d3f7a9 100644 --- a/lib/salet.coffee +++ b/lib/salet.coffee @@ -235,7 +235,7 @@ class Salet @linkStack = [] # Handle each link in turn. - @processOneLink(code); + @processOneLink(code) while (@linkStack.length > 0) code = @linkStack.shift() @processOneLink(code) @@ -260,7 +260,9 @@ class Salet ### @processOneLink = (code) => match = code.match(@linkRe) - assert(match, "link_not_valid".l({link:code})) + if not match + console.error "link_not_valid".l() + console.error code situation = match[1] action = match[3] @@ -295,6 +297,11 @@ class Salet @progress.sequence.push({link:code, when:@time}) @processLink(code) + # Presumably, the last action is the one that fired goBack, so we go to the + # one before it. + @goBack = (steps = 2) => + @processClick(@progress.sequence[@progress.sequence.length - steps].link) + # Transition between rooms. @doTransitionTo = (newRoomId) => oldRoomId = @current diff --git a/lib/view.coffee b/lib/view.coffee index 547f3d0..11d88c0 100644 --- a/lib/view.coffee +++ b/lib/view.coffee @@ -26,7 +26,7 @@ addClass = (element, className) -> class SaletView init: (salet) => - $("#content, #ways").on("click", "a", (event) -> + $("#content, #ways, #buttons").on("click", "a", (event) -> event.preventDefault() a = $(this) href = a.attr('href') diff --git a/sass/main.scss b/sass/main.scss index e3b2811..4e7c30a 100644 --- a/sass/main.scss +++ b/sass/main.scss @@ -29,7 +29,6 @@ body { @media (min-width: breakpoint-min(sm)) { @include make-col-offset(1); } - cursor: pointer; // Until we click to start. .label { overflow: hidden; margin: auto; @@ -143,16 +142,13 @@ body { } } #legal { - @include col(10,12); - @media (min-width: breakpoint-min(sm)) { - @include make-col-offset(1); - } margin-top: 1em; color: darken($body-color, 10%); font-size: smaller; #footleft { @media (min-width: breakpoint-min(sm)) { - @include make-col(10); + @include make-col-offset(2); + @include make-col(5); } @media (max-width: breakpoint-max(xs)) { @include make-col(12); @@ -161,7 +157,7 @@ body { #footright { text-align: right; @media (min-width: breakpoint-min(sm)) { - @include make-col(2); + @include make-col(4); } @media (max-width: breakpoint-max(xs)) { @include make-col(12); @@ -170,11 +166,6 @@ body { } } -#content_library, -#ui_library { - display: none; -} - .way { color: $waycolor; margin-right: 1em; @@ -215,3 +206,7 @@ hr { .fadeIn { animation-name: fadeIn; } + +.center { + text-align: center; +}