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

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

View file

@ -58,7 +58,7 @@ dialogue "Dialogue functions", "question2", "world", """
room "world", room "world",
tags: ["world"], tags: ["world"],
optionText: "Enter the world", optionText: "Enter the world",
ways: ["university"] ways: ["plaza"]
content: """ content: """
### Rhinestone Room ### Rhinestone Room
@ -70,17 +70,60 @@ room "world",
writers: writers:
well: "There is only one passage out. See the „Other rooms“ block popped up? Click it." 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: () -> 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: """ 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: """ 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) -> objlink = (content, ref) ->
return "<a href='./_act_#{ref}'>#{content}</a>" return "<a href='./_act_#{ref}'>#{content}</a>"
Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1
class RaconteurObj class RaconteurObj
constructor: (spec) -> constructor: (spec) ->
for key, value of spec for key, value of spec
@ -21,9 +23,13 @@ class RaconteurObj
take: () -> "You take the #{@name}." # taking to inventory take: () -> "You take the #{@name}." # taking to inventory
act: () -> "You don't find anything extraordinary about the #{@name}." # object action act: () -> "You don't find anything extraordinary about the #{@name}." # object action
dsc: () -> "You see a {{#{@name}}} here." # object description dsc: () -> "You see a {{#{@name}}} here." # object description
put: (room) -> location: ""
put: (location) ->
@level = 0 # this is scenery @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) -> obj = (name, spec) ->
spec ?= {} spec ?= {}

View file

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

View file

@ -27,11 +27,6 @@ markdown = require('./markdown.coffee')
Function.prototype.fcall = Function.prototype.call; Function.prototype.fcall = Function.prototype.call;
String.prototype.fcall = () -> return this 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 The prototype RaconteurSituation is the basic spec for situations
created with Raconteur. It should be able to handle any use case for Undum. 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 = { responses = {
writer: (ref) -> writer: (ref) ->
content = that.writers[ref].fcall(that, character, system, action) content = that.writers[ref].fcall(that, character, system, action)
output = markdown(content).fade() output = markdown(content)
system.writeInto(output, '#current-situation') system.writeInto(output, '#current-situation')
replacer: (ref) -> replacer: (ref) ->
content = that.writers[ref].fcall(that, character, system, action) 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) system.replaceWith(output, '#'+ref)
inserter: (ref) -> inserter: (ref) ->
content = that.writers[ref].fcall(that, character, system, action) content = that.writers[ref].fcall(that, character, system, action)
output = markdown(content).fade() output = markdown(content)
system.writeInto(output, '#'+ref) system.writeInto(output, '#'+ref)
} }