Story WIP

This commit is contained in:
Alexander Yakovlev 2016-01-15 22:29:15 +07:00
parent b05b2974c7
commit 9eb9a011bf
5 changed files with 80 additions and 30 deletions

View file

@ -23,14 +23,17 @@ actlink = (content, ref) ->
textcycle = (content, ref) ->
return "<a href='./_replacer_#{ref}' class='cycle' id='#{ref}'>#{content}</a>"
###
This function clears the screen.
The full backlog makes sense in dialogues but it's clunky when you exploring.
So this is manual cls
###
cls = () ->
document.getElementById("intro").innerHTML = ""
document.getElementById("content").innerHTML = ""
# Cycling link. It's implied there can be only one per situation.
# You are welcome to improve this code.
cycle = (obj, character) ->
responses = obj.cycle_gallery()
character.sandbox.cycle_index ?= [] # initialize with empty array
character.sandbox.cycle_index[obj.name] ?= 0 # initialize with 0
response = responses[character.sandbox.cycle_index[obj.name]]
character.sandbox.cycle_index[obj.name]++
if character.sandbox.cycle_index[obj.name] == responses.length
character.sandbox.cycle_index[obj.name] = 0
return textcycle(response, 'cyclewriter')
# usage: writemd( system, "Text to write")
writemd = (system, text) ->

View file

@ -58,7 +58,7 @@ dialogue "Dialogue functions", "question2", "world", """
room "world",
tags: ["world"],
optionText: "Enter the world",
ways: ["university"]
ways: ["plaza"]
content: """
### Rhinestone Room
@ -70,17 +70,60 @@ room "world",
writers:
well: "There is only one passage out. See the „Other rooms“ block popped up? Click it."
room "university",
room "plaza",
title: (from) ->
if from == "world"
return "Upwards"
else
return "Town plaza"
cycle_gallery: () ->
return [
"quirky", "distinct", "kooky", "crazy", "quaint"
]
ways: ["shop"]
before: () ->
undum.game.situations["supermarket"].destination()
"""
You leave the University.
You climb up the well and come out to a central plaza of a #{textcycle("quaint", "cyclewriter")} little town.
A plaque nearby says it's the town of *Innsmouth,* wherever that is.
"""
content: """
Okay, now to the supermarket.
You are
There are #{textlink("people shouting", "people")} nearby.
You could ask a policeman #{textlink("for directions.", "mark")}
"""
writers:
cyclewriter: (character) -> cycle(this, character)
mark: (character) ->
if character.sandbox.has_mark?
return "You already talked to him, no need to bug the man twice."
character.sandbox.has_mark ?= true
undum.game.situations["lair"].destination()
"""
Here, let me mark it on your map.
"""
people: 'Just some weirdos shouting "Viva la Cthulhu!". Typical.'
room "shop",
title: "The Shop"
ways: ["plaza", "lair"]
content: """
Being the only shop in town, this trendy establishment did not need a name.
It's an open question why it had one, especially because its name was "Hung Crossing".
You are standing in front of a picturesque sign. It's cold here.
"""
room "supermarket",
room "lair",
ways: ["shop"]
title: "The Lair"
content: """
A trendy supermarket.
The Lair of Yog-Sothoth is a very *n'gai* cave, full of *buggs-shoggogs* and *n'ghaa ng'aa*.
"""
bugg = obj "bugg-shoggog",
dsc: "You see a particularly beautiful slimy {{bugg.}}"
act: () ->
this.delete()
return "You eat the bugg mass. Delicious and raw."
bugg.put("lair")

View file

@ -3,6 +3,8 @@ undum = require('./undum.js')
objlink = (content, ref) ->
return "<a href='./_act_#{ref}'>#{content}</a>"
Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1
class RaconteurObj
constructor: (spec) ->
for key, value of spec
@ -21,9 +23,13 @@ class RaconteurObj
take: () -> "You take the #{@name}." # taking to inventory
act: () -> "You don't find anything extraordinary about the #{@name}." # object action
dsc: () -> "You see a {{#{@name}}} here." # object description
put: (room) ->
location: ""
put: (location) ->
@level = 0 # this is scenery
undum.game.situations[room].objects[@name] = this
undum.game.situations[location].objects[@name] = this
@location = location
delete: () ->
undum.game.situations[@location].objects.remove(this)
obj = (name, spec) ->
spec ?= {}

View file

@ -31,14 +31,14 @@ addClass = (element, className) ->
here = () ->
return undum.game.situations[document.getElementById("current-situation").getAttribute("data-situation")]
update_ways = (ways) ->
update_ways = (ways, name) ->
content = ""
distances = []
if ways
document.querySelector(".ways h2").style.display = "block"
for way in ways
if undum.game.situations[way]?
title = undum.game.situations[way].name
title = undum.game.situations[way].title.fcall(this, name)
content += way_to(title, way)
distances.push({
key: way
@ -74,7 +74,10 @@ class SaletRoom extends RaconteurSituation
@writers = spec.writers
if spec.extendSection?
@extendSection = spec.extendSection
if spec.title?
@title = spec.title
return this
title: "Room"
objects: []
extendSection: false
distance: Infinity # distance to the destination
@ -133,13 +136,13 @@ class SaletRoom extends RaconteurSituation
current_situation = "<section id='current-situation' data-situation='#{@name}' class='situation-#{@name}#{classes}'>"
if f != @name and @before?
current_situation += @before.fcall(this, character, system, f)
current_situation += markdown(@before.fcall(this, character, system, f))
if @look
current_situation += @look character, system, f
if f != @name and @after?
current_situation += @after.fcall(this, character, system, f)
current_situation += markdown(@after.fcall(this, character, system, f))
if not @extendSection
current_situation += "</section>"
@ -150,7 +153,7 @@ class SaletRoom extends RaconteurSituation
system.writeChoices(system.getSituationIdChoices(@choices, @minChoices, @maxChoices))
look: (character, system, f) ->
update_ways(@ways)
update_ways(@ways, @name)
retval = ""
# Print the room description

View file

@ -27,11 +27,6 @@ markdown = require('./markdown.coffee')
Function.prototype.fcall = Function.prototype.call;
String.prototype.fcall = () -> return this
#Adds the "fadeIn" class to a htmlString.
#The class "fade" is redefined by Bootstrap, so it's not the best choice.
String.prototype.fade = () ->
return '<div class="fadeIn">'+this+'</div>'
###
The prototype RaconteurSituation is the basic spec for situations
created with Raconteur. It should be able to handle any use case for Undum.
@ -68,15 +63,15 @@ RaconteurSituation.prototype.act = (character, system, action) ->
responses = {
writer: (ref) ->
content = that.writers[ref].fcall(that, character, system, action)
output = markdown(content).fade()
output = markdown(content)
system.writeInto(output, '#current-situation')
replacer: (ref) ->
content = that.writers[ref].fcall(that, character, system, action)
output = markdown(content).fade()
output = "<span>"+content+"</span>" # <p> tags are usually bad for replacers
system.replaceWith(output, '#'+ref)
inserter: (ref) ->
content = that.writers[ref].fcall(that, character, system, action)
output = markdown(content).fade()
output = markdown(content)
system.writeInto(output, '#'+ref)
}