Skip to content

Commit

Permalink
Fixes that objects can call ctrl.list() with themselves.
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed Oct 29, 2023
1 parent dee9e1b commit 22dc61a
Showing 1 changed file with 61 additions and 27 deletions.
88 changes: 61 additions & 27 deletions lib/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ const EntTraits = (function() {
{
}

// showObjectsInside ------------------------------------
/** @return whether the subobjects should be listed when describing the loc. */
function isListingObjectsInside()
{
return this.listObjectsInside;
}

function setListsObjectsInside(v)
{
if ( arguments.length === 0 ) {
v = true;
}

this.locListObjectsInside = v;
}

// Scenery ----------------------
/** @return whether the object is scenery or not. */
function isScenery()
Expand Down Expand Up @@ -272,6 +288,9 @@ const EntTraits = (function() {
// constructor & ini
"ctor": ctor,
"ini": ini,
// showObjectsInside
"isListingObjectsInside": isListingObjectsInside,
"setListsObjectsInside": setListsObjectsInside,
// Scenery
"isScenery": isScenery,
"esEscenario": isScenery,
Expand Down Expand Up @@ -318,27 +337,12 @@ const EntTraits = (function() {
};
})();

EntTraits.listObjectsInside = true;
const Ent = EntTraits; // Compatibility


/** The common traits for locations. */
const LocTraits = (function() {
// showObjectsInside ------------------------------------
/** @return whether the subobjects should be listed when describing the loc. */
function isLocListingObjectsInside()
{
return this.locListObjectsInside;
}

function setLocListsObjectsInside(v)
{
if ( arguments.length === 0 ) {
v = true;
}

this.locListObjectsInside = v;
}

// Triggers with each turn ----------------------------
function doEachTurn()
{
Expand Down Expand Up @@ -463,9 +467,6 @@ const LocTraits = (function() {
}

return {
// showObjectsInside
"isLocListingObjectsInside": isLocListingObjectsInside,
"setLocListsObjectsInside": setLocListsObjectsInside,
// doEachTurn
"doEachTurn": doEachTurn,
"hazCadaTurno": doEachTurn,
Expand Down Expand Up @@ -497,7 +498,6 @@ const LocTraits = (function() {
};
})();
LocTraits.__proto__ = EntTraits;
LocTraits.locListObjectsInside = true;


/** Represents locations, i.e., the entrance to a cave. */
Expand Down Expand Up @@ -1914,9 +1914,19 @@ const ctrl = ( function() {
current = l;
}

function creaLoc(id, syn, desc)
/** Creates a Loc.
* @param id the word that acts as id, i.e. "bedroom"
* @param syn a list of synonyms, i.e., [ "dorm" ]
* @param desc a text describing the Loc, i.e. "Comfy."
* @param ini a function to be executed at the beginning of the game.
*/
function creaLoc(id, syn, desc, ini)
{
const toret = new Loc( locs.length, id, syn, desc );

if ( ini != null ) {
toret.ini = ini;
}

locs.push( toret );
return toret;
Expand Down Expand Up @@ -2183,11 +2193,24 @@ const ctrl = ( function() {
};
})();

function creaObj(id, syn, desc, loc, isScenery)
{
/** Creates an object.
* @param id the word that acts as id, i.e. "lamp"
* @param syn a list of synonyms, i.e., [ "light" ]
* @param desc a text describing the object, i.e. "Gives light."
* @param loc the loc this object pertaints to, i.e. LOC_ROOM
* @param isScenery a boolean value.
* @param ini a function to be executed at the beginning of the game.
*/
function creaObj(id, syn, desc, loc, isScenery, ini)
{
const toret = new Obj( loc.objs.length, id, syn, loc, desc );

if ( ini != null ) {
toret.ini = ini;
}

toret.setScenery( isScenery );

loc.objs.push( toret );
return toret;
}
Expand All @@ -2196,10 +2219,21 @@ const ctrl = ( function() {
const personas = [];
var player = null;

function creaPersona(id, syn, desc, loc)
/** Creates a character.
* @param id the word that acts as id, i.e. "Bob"
* @param syn a list of synonyms, i.e., [ "clerk" ]
* @param desc a text describing the object, i.e. "Waiting."
* @param loc the loc this object pertaints to, i.e. LOC_ROOM
* @param ini a function to be executed at the beginning of the game.
*/
function creaPersona(id, syn, desc, loc, ini)
{
const toret = new Persona( personas.length, id, syn, loc, desc );

if ( ini != null ) {
toret.ini = ini;
}

loc.personas.push( toret );
personas.push( toret );
return toret;
Expand Down Expand Up @@ -2485,8 +2519,8 @@ const ctrl = ( function() {
return listVector( personas, talkAction.verbs[ 0 ] );
}

/** Lists all objects inside a Loc
* @param loc The Loc
/** Lists all objects inside a Loc or Obj
* @param loc The Loc or Obj
*/
function list(loc)
{
Expand All @@ -2500,7 +2534,7 @@ const ctrl = ( function() {
}

if ( loc == player
|| loc.isLocListingObjectsInside() )
|| loc.isListingObjectsInside() )
{
const EX_ACT = actions.getAction( "examine" ).verbs[ 0 ];
const TAKE_ACT = actions.getAction( "take" ).verbs[ 0 ];
Expand Down

0 comments on commit 22dc61a

Please sign in to comment.