1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-04 07:45:03 +03:00

Resolves #20 - proper inventory, list of carried things

This commit is contained in:
Alexander Yakovlev 2016-03-20 20:46:40 +07:00
parent b621ef2643
commit 6dd06d2b89
8 changed files with 66 additions and 31 deletions

View file

@ -34,3 +34,22 @@ room "start", salet,
dsc: """ dsc: """
""", """,
choices: "#start" 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"+"""
<div class="center"><a href="plaza"><button class="btn btn-lg btn-outline-primary">Go to plaza</button></a></div>
"""

View file

@ -58,20 +58,19 @@
</div> </div>
</div> <!-- End of div.tools_wrapper --> </div> <!-- End of div.tools_wrapper -->
<div class="row"> <div id="legal" class="row">
<div id="legal"> <div id="footleft">
<div id="footleft"> <p>The game was written by <em>(you should put your name here)</em></p>
<p>The game was written by <em>(you should put your name here)</em></p> <p>Approximate play time: not measured.</p>
<p>Approximate play time: not measured.</p> <p>Written using <a href="http://git.oreolek.ru/oreolek/salet" target="_blank">Salet</a>.</p>
<p>Written using <a href="http://git.oreolek.ru/oreolek/salet" target="_blank">Salet</a>.</p> <p>Betatesting credit: none yet</p>
<p>Betatesting credit: none yet</p> </div>
</div> <div id="footright">
<div id="footright"> <p id='buttons'>
<p class='buttons'> <a href="inventory"><button id="inventory" class="btn btn-outline-primary">Inventory</button></a>
<button id="erase" class="btn btn-outline-danger">Restart</button> <button id="erase" class="btn btn-outline-danger">Restart</button>
</p> </p>
<p><a href="./LICENSE.txt"><img src="img/mit.png" alt="This program is licensed under MIT license."></a></p> <p><a href="./LICENSE.txt"><img src="img/mit.png" alt="This program is licensed under MIT license."></a></p>
</div>
</div> </div>
</div> </div>
</div> <!-- End of div.page --> </div> <!-- End of div.page -->

View file

@ -1,3 +1,6 @@
invlink = (content, ref) ->
return "<a href='./_inv_#{ref}' class='once'>#{content}</a>"
class Character class Character
constructor: (spec) -> constructor: (spec) ->
@inventory = [] @inventory = []
@ -16,6 +19,16 @@ class Character
return true return true
return false 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 for index, value of spec
this[index] = value this[index] = value
return this return this

View file

@ -32,7 +32,7 @@ class SaletObj
@take = (system) => "You take the #{@name}." # taking to inventory @take = (system) => "You take the #{@name}." # taking to inventory
@act = (system) => "You don't find anything extraordinary about the #{@name}." # object action @act = (system) => "You don't find anything extraordinary about the #{@name}." # object action
@dsc = (system) => "You see a {{#{@name}}} here." # object description @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 = "" @location = ""
@put = (salet, location) => @put = (salet, location) =>
@level = 0 # this is scenery @level = 0 # this is scenery

View file

@ -155,7 +155,9 @@ class SaletRoom
You could interpret this as an EXAMINE verb or USE one, it's your call. You could interpret this as an EXAMINE verb or USE one, it's your call.
### ###
@act = (system, action) => @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 for thing in @objects
if thing.name == link[2] if thing.name == link[2]
if link[1] == "act" if link[1] == "act"

View file

@ -235,7 +235,7 @@ class Salet
@linkStack = [] @linkStack = []
# Handle each link in turn. # Handle each link in turn.
@processOneLink(code); @processOneLink(code)
while (@linkStack.length > 0) while (@linkStack.length > 0)
code = @linkStack.shift() code = @linkStack.shift()
@processOneLink(code) @processOneLink(code)
@ -260,7 +260,9 @@ class Salet
### ###
@processOneLink = (code) => @processOneLink = (code) =>
match = code.match(@linkRe) 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] situation = match[1]
action = match[3] action = match[3]
@ -295,6 +297,11 @@ class Salet
@progress.sequence.push({link:code, when:@time}) @progress.sequence.push({link:code, when:@time})
@processLink(code) @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. # Transition between rooms.
@doTransitionTo = (newRoomId) => @doTransitionTo = (newRoomId) =>
oldRoomId = @current oldRoomId = @current

View file

@ -26,7 +26,7 @@ addClass = (element, className) ->
class SaletView class SaletView
init: (salet) => init: (salet) =>
$("#content, #ways").on("click", "a", (event) -> $("#content, #ways, #buttons").on("click", "a", (event) ->
event.preventDefault() event.preventDefault()
a = $(this) a = $(this)
href = a.attr('href') href = a.attr('href')

View file

@ -29,7 +29,6 @@ body {
@media (min-width: breakpoint-min(sm)) { @media (min-width: breakpoint-min(sm)) {
@include make-col-offset(1); @include make-col-offset(1);
} }
cursor: pointer; // Until we click to start.
.label { .label {
overflow: hidden; overflow: hidden;
margin: auto; margin: auto;
@ -143,16 +142,13 @@ body {
} }
} }
#legal { #legal {
@include col(10,12);
@media (min-width: breakpoint-min(sm)) {
@include make-col-offset(1);
}
margin-top: 1em; margin-top: 1em;
color: darken($body-color, 10%); color: darken($body-color, 10%);
font-size: smaller; font-size: smaller;
#footleft { #footleft {
@media (min-width: breakpoint-min(sm)) { @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)) { @media (max-width: breakpoint-max(xs)) {
@include make-col(12); @include make-col(12);
@ -161,7 +157,7 @@ body {
#footright { #footright {
text-align: right; text-align: right;
@media (min-width: breakpoint-min(sm)) { @media (min-width: breakpoint-min(sm)) {
@include make-col(2); @include make-col(4);
} }
@media (max-width: breakpoint-max(xs)) { @media (max-width: breakpoint-max(xs)) {
@include make-col(12); @include make-col(12);
@ -170,11 +166,6 @@ body {
} }
} }
#content_library,
#ui_library {
display: none;
}
.way { .way {
color: $waycolor; color: $waycolor;
margin-right: 1em; margin-right: 1em;
@ -215,3 +206,7 @@ hr {
.fadeIn { .fadeIn {
animation-name: fadeIn; animation-name: fadeIn;
} }
.center {
text-align: center;
}