mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-07-07 01:04:25 +03:00
Fixed the prototype variables. Resolves #5.
This commit is contained in:
parent
07b994cc7f
commit
43c66af5a6
|
@ -8,10 +8,11 @@ room "world", salet,
|
||||||
You're in a large room carved inside a giant milky rock mountain.
|
You're in a large room carved inside a giant milky rock mountain.
|
||||||
The floor and walls are littered with signs and signatures of the previous visitors.
|
The floor and walls are littered with signs and signatures of the previous visitors.
|
||||||
"""
|
"""
|
||||||
objects:
|
objects: [
|
||||||
well: obj "well",
|
obj "well",
|
||||||
dsc: "A steep narrow {{well}} proceeds upward."
|
dsc: "A steep narrow {{well}} proceeds upward."
|
||||||
act: "There is only one passage out. See the „Other rooms“ block popped up? Click it."
|
act: "There is only one passage out. See the „Other rooms“ block popped up? Click it."
|
||||||
|
]
|
||||||
|
|
||||||
room "plaza", salet,
|
room "plaza", salet,
|
||||||
title: (from) ->
|
title: (from) ->
|
||||||
|
@ -29,8 +30,8 @@ room "plaza", salet,
|
||||||
"""
|
"""
|
||||||
else
|
else
|
||||||
"You quickly find the central plaza."
|
"You quickly find the central plaza."
|
||||||
objects:
|
objects: [
|
||||||
policeman: obj "policeman",
|
obj "policeman",
|
||||||
dsc: "There is a policeman nearby. You could ask him {{for directions.}}"
|
dsc: "There is a policeman nearby. You could ask him {{for directions.}}"
|
||||||
act: (salet) ->
|
act: (salet) ->
|
||||||
if salet.character.has_mark?
|
if salet.character.has_mark?
|
||||||
|
@ -40,9 +41,10 @@ room "plaza", salet,
|
||||||
"""
|
"""
|
||||||
“Here, let me mark it on your map.”
|
“Here, let me mark it on your map.”
|
||||||
"""
|
"""
|
||||||
people: obj "people",
|
obj "people",
|
||||||
dsc: "There are {{people shouting}} nearby."
|
dsc: "There are {{people shouting}} nearby."
|
||||||
act: 'Just some weirdos shouting "Viva la Cthulhu!". Typical.'
|
act: 'Just some weirdos shouting "Viva la Cthulhu!". Typical.'
|
||||||
|
]
|
||||||
|
|
||||||
room "shop", salet,
|
room "shop", salet,
|
||||||
title: "The Shop"
|
title: "The Shop"
|
||||||
|
@ -61,13 +63,15 @@ room "lair", salet,
|
||||||
dsc: """
|
dsc: """
|
||||||
The Lair of Yog-Sothoth is a very *n'gai* cave, full of *buggs-shoggogs* and *n'ghaa ng'aa*.
|
The Lair of Yog-Sothoth is a very *n'gai* cave, full of *buggs-shoggogs* and *n'ghaa ng'aa*.
|
||||||
"""
|
"""
|
||||||
objects:
|
ways: ["shop"]
|
||||||
bugg: obj "bugg",
|
objects: [
|
||||||
|
obj "bugg",
|
||||||
dsc: "You see a particularly beautiful slimy {{bugg.}}"
|
dsc: "You see a particularly beautiful slimy {{bugg.}}"
|
||||||
takeable: false
|
takeable: false
|
||||||
act: (salet) =>
|
act: (salet) =>
|
||||||
salet.here().drop(@name)
|
salet.rooms[salet.current].drop(@name)
|
||||||
return "You eat the bugg mass. Delicious and raw. Perhaps it's a good lair to live in."
|
return "You eat the bugg mass. Delicious and raw. Perhaps it's a good lair to live in."
|
||||||
|
]
|
||||||
|
|
||||||
dialogue "Yes", salet, "merchant", "merchant", """
|
dialogue "Yes", salet, "merchant", "merchant", """
|
||||||
Yes.
|
Yes.
|
||||||
|
@ -81,25 +85,25 @@ room "shop-inside", salet,
|
||||||
dsc: """
|
dsc: """
|
||||||
The insides are painted pastel white, honouring The Great Milk Spill of 1985.
|
The insides are painted pastel white, honouring The Great Milk Spill of 1985.
|
||||||
"""
|
"""
|
||||||
objects:
|
objects: [
|
||||||
merchant: obj "merchant",
|
merchant: obj "merchant",
|
||||||
dsc: "A {{merchant}} eyes you warily."
|
dsc: "A {{merchant}} eyes you warily."
|
||||||
takeable: false
|
takeable: false
|
||||||
act: (system) =>
|
act: (system) =>
|
||||||
salet.processClick("merchdialogue")
|
salet.processClick("merchdialogue")
|
||||||
return ""
|
return ""
|
||||||
|
]
|
||||||
|
|
||||||
###
|
###
|
||||||
I want to be able to do this but I can't because I'm lost in all the `this` and @objects and `new`.
|
I want to be able to do this but I can't because I'm lost in all the `this` and @objects and `new`.
|
||||||
The chain of calls is very weird and this puts an object IN EVERY ROOM for God's sake.
|
The chain of calls is very weird and this puts an object IN EVERY ROOM for God's sake.
|
||||||
I need someone smarter than me to fix this.
|
I need someone smarter than me to fix this.
|
||||||
|
|
||||||
lamp = obj "lamp",
|
|
||||||
dsc: "You see a {{lamp.}}"
|
|
||||||
takeable: true
|
|
||||||
lamp.put("shop-inside")
|
|
||||||
###
|
###
|
||||||
|
|
||||||
|
lamp = obj "lamp", salet,
|
||||||
|
takeable: true
|
||||||
|
lamp.put(salet, "shop-inside")
|
||||||
|
|
||||||
room "merchdialogue", salet,
|
room "merchdialogue", salet,
|
||||||
choices: "#merchant",
|
choices: "#merchant",
|
||||||
dsc: """
|
dsc: """
|
||||||
|
|
|
@ -20,32 +20,34 @@ class SaletObj
|
||||||
unless spec.name?
|
unless spec.name?
|
||||||
console.error("Trying to create an object with no name")
|
console.error("Trying to create an object with no name")
|
||||||
return null
|
return null
|
||||||
for key, value of spec
|
|
||||||
this[key] = value
|
@level = 0 # if > 0 it's hidden
|
||||||
level: 0 # if > 0 it's hidden
|
@order = 0 # you can use this to sort the descriptions
|
||||||
order: 0 # you can use this to sort the descriptions
|
@look = (system, f) =>
|
||||||
look: (system, f) =>
|
|
||||||
if @dsc and @dsc != ""
|
if @dsc and @dsc != ""
|
||||||
text = markdown(@dsc.fcall(this, system, f).toString())
|
text = markdown(@dsc.fcall(this, system, f).toString())
|
||||||
text = system.view.wrapLevel(text, @level)
|
text = system.view.wrapLevel(text, @level)
|
||||||
# replace braces {{}} with link to _act_
|
# replace braces {{}} with link to _act_
|
||||||
return parsedsc(text, @name)
|
return parsedsc(text, @name)
|
||||||
takeable: false
|
@takeable = false
|
||||||
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: (location) =>
|
@put = (salet, location) =>
|
||||||
@level = 0 # this is scenery
|
@level = 0 # this is scenery
|
||||||
if salet.rooms[location]?
|
if salet.rooms[location]?
|
||||||
salet.rooms[location].take(this)
|
|
||||||
@location = location
|
@location = location
|
||||||
delete: (location = false) =>
|
salet.rooms[location].take(this)
|
||||||
|
@delete = (salet, location = false) =>
|
||||||
if location == false
|
if location == false
|
||||||
location = @location
|
location = @location
|
||||||
salet.rooms[location].drop(this)
|
salet.rooms[location].drop(this)
|
||||||
|
|
||||||
|
for key, value of spec
|
||||||
|
this[key] = value
|
||||||
|
|
||||||
obj = (name, spec) ->
|
obj = (name, spec) ->
|
||||||
spec ?= {}
|
spec ?= {}
|
||||||
spec.name = name
|
spec.name = name
|
||||||
|
|
|
@ -19,37 +19,30 @@ Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1
|
||||||
|
|
||||||
class SaletRoom
|
class SaletRoom
|
||||||
constructor: (spec) ->
|
constructor: (spec) ->
|
||||||
for index, value of spec
|
@visited = 0
|
||||||
this[index] = value
|
@title = "Room"
|
||||||
return this
|
@objects = {}
|
||||||
visited: 0
|
@canView = true
|
||||||
title: "Room"
|
@canChoose = true
|
||||||
objects: {}
|
@priority = 1
|
||||||
|
@displayOrder = 1
|
||||||
|
@tags = []
|
||||||
|
@choices = ""
|
||||||
|
@optionText = "Choice"
|
||||||
|
|
||||||
# room illustration image, VN-style. Can be a GIF or WEBM. Can be a function.
|
# room illustration image, VN-style. Can be a GIF or WEBM. Can be a function.
|
||||||
pic: false
|
@pic = false
|
||||||
|
@dsc = false # room description
|
||||||
canView: true
|
@extendSection = false
|
||||||
canChoose: true
|
@distance = Infinity # distance to the destination
|
||||||
priority: 1
|
@clear = true # clear the screen on entering the room?
|
||||||
displayOrder: 1
|
@entering = (system, from) =>
|
||||||
tags: []
|
|
||||||
choices: ""
|
|
||||||
optionText: "Choice"
|
|
||||||
|
|
||||||
dsc: false # room description
|
|
||||||
extendSection: false
|
|
||||||
distance: Infinity # distance to the destination
|
|
||||||
clear: true # clear the screen on entering the room?
|
|
||||||
|
|
||||||
entering: (system, from) =>
|
|
||||||
|
|
||||||
###
|
###
|
||||||
I call SaletRoom.exit every time the player exits to another room.
|
I call SaletRoom.exit every time the player exits to another room.
|
||||||
Unlike @after this gets called after the section is closed.
|
Unlike @after this gets called after the section is closed.
|
||||||
It's a styling difference.
|
It's a styling difference.
|
||||||
###
|
###
|
||||||
exit: (system, to) =>
|
@exit = (system, to) =>
|
||||||
return true
|
return true
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -60,7 +53,7 @@ class SaletRoom
|
||||||
The upstream Undum version does not allow you to redefine @enter function easily but allows custom @exit one.
|
The upstream Undum version does not allow you to redefine @enter function easily but allows custom @exit one.
|
||||||
It was renamed as @entering to achieve API consistency.
|
It was renamed as @entering to achieve API consistency.
|
||||||
###
|
###
|
||||||
enter: (system, from) =>
|
@enter = (system, from) =>
|
||||||
return true
|
return true
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -72,7 +65,7 @@ class SaletRoom
|
||||||
My version of `enter` splits the location description from the effects.
|
My version of `enter` splits the location description from the effects.
|
||||||
Also if f == this.name (we're in the same location) the `before` and `after` callbacks are ignored.
|
Also if f == this.name (we're in the same location) the `before` and `after` callbacks are ignored.
|
||||||
###
|
###
|
||||||
entering: (system, f) =>
|
@entering = (system, f) =>
|
||||||
if @clear and f?
|
if @clear and f?
|
||||||
system.view.clearContent()
|
system.view.clearContent()
|
||||||
|
|
||||||
|
@ -118,7 +111,7 @@ class SaletRoom
|
||||||
An internal function to get the room's description and the descriptions of
|
An internal function to get the room's description and the descriptions of
|
||||||
every object in this room.
|
every object in this room.
|
||||||
###
|
###
|
||||||
look: (system, f) =>
|
@look = (system, f) =>
|
||||||
system.view.updateWays(system, @ways, @name)
|
system.view.updateWays(system, @ways, @name)
|
||||||
retval = ""
|
retval = ""
|
||||||
|
|
||||||
|
@ -132,7 +125,6 @@ class SaletRoom
|
||||||
|
|
||||||
objDescriptions = []
|
objDescriptions = []
|
||||||
for thing in @objects
|
for thing in @objects
|
||||||
console.log thing
|
|
||||||
if thing.name and typeof(thing.look) == "function" and thing.level == 0 and thing.look(system, f)
|
if thing.name and typeof(thing.look) == "function" and thing.level == 0 and thing.look(system, f)
|
||||||
objDescriptions.push ({
|
objDescriptions.push ({
|
||||||
order: thing.order,
|
order: thing.order,
|
||||||
|
@ -151,20 +143,20 @@ class SaletRoom
|
||||||
###
|
###
|
||||||
Puts an object in this room.
|
Puts an object in this room.
|
||||||
###
|
###
|
||||||
take: (thing) =>
|
@take = (thing) =>
|
||||||
@objects[thing.name] = thing
|
@objects[thing.name] = thing
|
||||||
# BUG: for some really weird reason if the call is made in init function or
|
|
||||||
# during the initialization, this ALSO puts the thing in the start room.
|
|
||||||
salet.rooms["start"].objects = {}
|
|
||||||
|
|
||||||
drop: (name) =>
|
@drop = (name) =>
|
||||||
delete @objects[name]
|
for thing in @objects
|
||||||
|
if thing.name == name
|
||||||
|
index = @objects.indexOf(thing)
|
||||||
|
@objects.splice(index, 1)
|
||||||
|
|
||||||
###
|
###
|
||||||
Object action. A function or a string which comes when you click on the object link.
|
Object action. A function or a string which comes when you click on the object link.
|
||||||
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)_(.+)$/)) #object action
|
||||||
for thing in @objects
|
for thing in @objects
|
||||||
if thing.name == link[2]
|
if thing.name == link[2]
|
||||||
|
@ -219,7 +211,7 @@ class SaletRoom
|
||||||
throw new Error("Tried to call undefined action: #{action}");
|
throw new Error("Tried to call undefined action: #{action}");
|
||||||
|
|
||||||
# Marks every room in the game with distance to this room
|
# Marks every room in the game with distance to this room
|
||||||
destination: () =>
|
@destination = () =>
|
||||||
@distance = 0
|
@distance = 0
|
||||||
|
|
||||||
candidates = [this]
|
candidates = [this]
|
||||||
|
@ -231,14 +223,14 @@ class SaletRoom
|
||||||
node.distance = current_room.distance + 1
|
node.distance = current_room.distance + 1
|
||||||
candidates.push(node)
|
candidates.push(node)
|
||||||
|
|
||||||
register: (salet) =>
|
@register = (salet) =>
|
||||||
if not @name?
|
if not @name?
|
||||||
console.error("Situation has no name")
|
console.error("Situation has no name")
|
||||||
return this
|
return this
|
||||||
salet.rooms[@name] = this
|
salet.rooms[@name] = this
|
||||||
return this
|
return this
|
||||||
|
|
||||||
writers:
|
@writers = {
|
||||||
cyclewriter: (salet) =>
|
cyclewriter: (salet) =>
|
||||||
responses = @cycle
|
responses = @cycle
|
||||||
if typeof responses == "function"
|
if typeof responses == "function"
|
||||||
|
@ -251,6 +243,11 @@ class SaletRoom
|
||||||
cycleIndex = 0
|
cycleIndex = 0
|
||||||
window.localStorage.setItem("cycleIndex", cycleIndex)
|
window.localStorage.setItem("cycleIndex", cycleIndex)
|
||||||
return salet.view.cycleLink(response)
|
return salet.view.cycleLink(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
for index, value of spec
|
||||||
|
this[index] = value
|
||||||
|
return this
|
||||||
|
|
||||||
room = (name, salet, spec) ->
|
room = (name, salet, spec) ->
|
||||||
spec ?= {}
|
spec ?= {}
|
||||||
|
|
|
@ -23,6 +23,8 @@ class Character
|
||||||
###
|
###
|
||||||
This is the control structure, it has minimal amount of data and
|
This is the control structure, it has minimal amount of data and
|
||||||
this data is volatile anyway (as in, it won't get saved).
|
this data is volatile anyway (as in, it won't get saved).
|
||||||
|
|
||||||
|
There is only one instance of this class.
|
||||||
###
|
###
|
||||||
class Salet
|
class Salet
|
||||||
# REDEFINE THIS IN YOUR GAME
|
# REDEFINE THIS IN YOUR GAME
|
||||||
|
|
|
@ -9,6 +9,8 @@ You don't need to call this module from the game directly.
|
||||||
The abstraction goal here is to provide the author with a freedom to style his
|
The abstraction goal here is to provide the author with a freedom to style his
|
||||||
game as he wants to. The save and erase buttons are not necessary buttons,
|
game as he wants to. The save and erase buttons are not necessary buttons,
|
||||||
but they could be something else entirely. (That's why IDs are hardcoded.)
|
but they could be something else entirely. (That's why IDs are hardcoded.)
|
||||||
|
|
||||||
|
There is only one instance of this class, and it's stored as `salet.view`.
|
||||||
###
|
###
|
||||||
|
|
||||||
assert = (msg, assertion) -> console.assert assertion, msg
|
assert = (msg, assertion) -> console.assert assertion, msg
|
||||||
|
|
Loading…
Reference in a new issue