0
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet-module.git synced 2024-06-26 03:50:49 +03:00

Code comments, API fixes, no stray pathfinding

This commit is contained in:
Alexander Yakovlev 2016-12-08 08:33:16 +07:00
parent 748b9c0e4d
commit 70d8f80c5d
4 changed files with 40 additions and 47 deletions

View file

@ -1,6 +1,6 @@
{
"name": "salet",
"version": "1.6.3",
"version": "1.6.4",
"description": "A general client-side framework for cybertext interactive fiction games.",
"keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"],
"homepage": "http://salet.oreolek.ru",

View file

@ -1,7 +1,12 @@
class SaletRoom
constructor: (spec) ->
@visited = 0
# unique room ID, mandatory to edit
@name = "Room"
# room title, used in waypoint generation, see @ways
@title = "Room"
@units = []
@canView = true
@canChoose = true
@ -10,6 +15,8 @@ class SaletRoom
@canSave = true
@canExit = true
@tags = []
# array of adjacent room IDs, printed as links. Link text to this room is @title.
@ways = []
@choices = ""
@optionText = "Choice"
@ -17,7 +24,6 @@ class SaletRoom
@pic = false
@dsc = false # room description
@extendSection = false
@distance = Infinity # distance to the destination
@clear = true # clear the screen on entering the room?
###
I call SaletRoom.exit every time the player exits to another room.
@ -39,7 +45,7 @@ class SaletRoom
return true
###
Salet calls Situation.entering every time a situation is entered, and
Salet calls SaletRoom.entering every time a situation is entered, and
passes it a string referencing the previous situation, or null if there is
none (ie, for the starting situation).
@ -203,22 +209,9 @@ class SaletRoom
else
throw new Error("Tried to call undefined action: #{action}");
# Marks every room in the game with distance to this room
@destination = () =>
@distance = 0
candidates = [this]
while candidates.length > 0
current_room = candidates.shift()
if current_room.ways
for node in current_room.ways
if node.distance == Infinity
node.distance = current_room.distance + 1
candidates.push(node)
@register = () =>
if not @name?
console.error("Situation has no name")
console.error("Room has no name")
return this
salet.rooms[@name] = this
return this

View file

@ -6,7 +6,7 @@ There is only one instance of this class.
###
class Salet
constructor: (spec) ->
@version = "1.5.0"
@version = "1.6.4"
@character = new Character
# REDEFINE THIS IN YOUR GAME
@ -34,69 +34,69 @@ class Salet
normally overridden to provide initial character creation
(setting initial quality values, setting the
character-text. This is optional, however, as set-up
processing could also be done by the first situation's
processing could also be done by the first room's
enter function.
###
@init = () ->
###
This function is called before entering any new
situation. It is called before the corresponding situation
room. It is called before the corresponding room
has its `enter` method called.
###
@enter = (oldSituationId, newSituationId) ->
###
Hook for when the situation has already been carried out
Hook for when the room has already been carried out
and printed.
###
@afterEnter = (oldSituationId, newSituationId) ->
###
This function is called before carrying out any action in
any situation. It is called before the corresponding
situation has its `act` method called.
any room. It is called before the corresponding
room has its `act` method called.
If the function returns true, then it is indicating that it
has consumed the action, and the action will not be passed
on to the situation. Note that this is the only one of
on to the room. Note that this is the only one of
these global handlers that can consume the event.
###
@beforeAction = (situationId, actionId) ->
###
This function is called after carrying out any action in
any situation. It is called after the corresponding
situation has its `act` method called.
any room. It is called after the corresponding
room has its `act` method called.
###
@afterAction = (situationId, actionId) ->
###
This function is called after leaving any situation. It is
called after the corresponding situation has its `exit`
This function is called after leaving any room. It is
called after the corresponding room has its `exit`
method called.
###
@exit = (oldSituationId, newSituationId) ->
###
Returns a list of situation ids to choose from, given a set of
Returns a list of room ids to choose from, given a set of
specifications.
This function is a complex and powerful way of compiling
implicit situation choices. You give it a list of situation ids
and situation tags (if a single id or tag is needed just that
implicit room choices. You give it a list of room ids
and room tags (if a single id or tag is needed just that
string can be given, it doesn't need to be wrapped in a
list). Tags should be prefixed with a hash # to differentiate
them from situation ids. The function then considers all
matching situations in descending priority order, calling their
them from room ids. The function then considers all
matching rooms in descending priority order, calling their
canView functions and filtering out any that should not be
shown, given the current state. Without additional parameters
the function returns a list of the situation ids at the highest
the function returns a list of the room ids at the highest
level of priority that has any valid results. So, for example,
if a tag #places matches three situations, one with priority 2,
if a tag #places matches three rooms, one with priority 2,
and two with priority 3, and all of them can be viewed in the
current context, then only the two with priority 3 will be
returned. This allows you to have high-priority situations that
returned. This allows you to have high-priority rooms that
trump any lower situations when they are valid, such as
situations that force the player to go to one destination if
the player is out of money, for example.
@ -203,8 +203,8 @@ class Salet
return null
# Gets the unique id used to identify saved games.
@getSaveId = (slot = "") ->
return 'salet_'+@game_id+'_'+@game_version#+'_'+slot
@getSaveId = () ->
return 'salet_'+@game_id+'_'+@game_version
# This gets called when a link needs to be followed, regardless
# of whether it was user action that initiated it.
@ -402,8 +402,8 @@ class Salet
@view = new SaletView
@getSave = (slot = "") ->
id = @getSaveId(slot)
@getSave = () ->
id = @getSaveId()
saveFile = false
if (@view.hasLocalStorage())
saveFile = localStorage.getItem(@getSaveId())

View file

@ -141,11 +141,11 @@ class SaletView
return true
###
Given a list of situation ids, this outputs a standard option
block with the situation choices in the given order.
Given a list of room ids, this outputs a standard option
block with the room choices in the given order.
The contents of each choice will be a link to the situation,
the text of the link will be given by the situation's
The contents of each choice will be a link to the room,
the text of the link will be given by the room's
outputText property. Note that the canChoose function is
called, and if it returns false, then the text will appear, but
the link will not be clickable.
@ -153,7 +153,7 @@ class SaletView
Although canChoose is honored, canView and displayOrder are
not. If you need to honor these, you should either do so
manually, ot else use the `getSituationIdChoices` method to
return an ordered list of valid viewable situation ids.
return an ordered list of valid viewable room ids.
###
@writeChoices = (listOfIds) ->
if (not listOfIds? or listOfIds.length == 0)
@ -181,7 +181,7 @@ class SaletView
# Marks all links as old. This gets called in a `processLink` function.
@mark_all_links_old = () ->
$('.new').removeClass('new')
$('#page .new').removeClass('new')
# Removes links and transient sections.
@removeTransient = (room = undefined) =>
@ -280,7 +280,7 @@ class SaletView
content = ""
if ways then for way in ways
if salet.rooms[way]?
title = salet.rooms[way].title.fcall(this, name)
title = salet.rooms[way].title.fcall(name)
content += "<li class='nav-item'><a class='nav-link' href='#{way}'>#{title}</a></li>"
@replace(content, "#ways")
@showBlock(".ways #ways_hint")