diff --git a/lib/fi.js b/lib/fi.js index 77fad3e..29e772d 100644 --- a/lib/fi.js +++ b/lib/fi.js @@ -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() @@ -272,6 +288,9 @@ const EntTraits = (function() { // constructor & ini "ctor": ctor, "ini": ini, + // showObjectsInside + "isListingObjectsInside": isListingObjectsInside, + "setListsObjectsInside": setListsObjectsInside, // Scenery "isScenery": isScenery, "esEscenario": isScenery, @@ -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() { @@ -463,9 +467,6 @@ const LocTraits = (function() { } return { - // showObjectsInside - "isLocListingObjectsInside": isLocListingObjectsInside, - "setLocListsObjectsInside": setLocListsObjectsInside, // doEachTurn "doEachTurn": doEachTurn, "hazCadaTurno": doEachTurn, @@ -497,7 +498,6 @@ const LocTraits = (function() { }; })(); LocTraits.__proto__ = EntTraits; -LocTraits.locListObjectsInside = true; /** Represents locations, i.e., the entrance to a cave. */ @@ -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; @@ -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; } @@ -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; @@ -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) { @@ -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 ];