Echo Hollow

Gender-Bending Interactive Stories! :D

User Tools

Site Tools


smutbook:classes:persistence:persistentobject

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
smutbook:classes:persistence:persistentobject [2023/08/08 14:17] – [.parent] leesmutbook:classes:persistence:persistentobject [2023/08/08 18:39] (current) lee
Line 1: Line 1:
 ====== PersistentObject ====== ====== PersistentObject ======
  
-**Inherits from:** Nothing+**Extends:** Nothing
  
 The PersistentObject is the class from which all of the more complex persistent data types are derived. People, Apparel, Transformable attributes, Inventories of various sorts, and many other classes of objects, are all are ultimately derived from PersistentObject. The PersistentObject is the class from which all of the more complex persistent data types are derived. People, Apparel, Transformable attributes, Inventories of various sorts, and many other classes of objects, are all are ultimately derived from PersistentObject.
Line 17: Line 17:
   * Funny business with subclass constructors.   * Funny business with subclass constructors.
   * Don't use strict equality because objects may be reallocated differently between game moments, because of the way SugarCube's game state history works.   * Don't use strict equality because objects may be reallocated differently between game moments, because of the way SugarCube's game state history works.
-===== Static Functions =====+ 
 +===== Static Properties/Functions =====
  
 Two static utility functions are defined on PersistentObject.  These are called through the global class name rather than through specific instances of objects. Two static utility functions are defined on PersistentObject.  These are called through the global class name rather than through specific instances of objects.
Line 24: Line 25:
 Defines the default data for a PersistentObject (or subclass thereof) within your game. PersistentObject.define() must only be called at initialization time, from story javascript or initialization passages.  The results of trying to use this function after the game has started are undefined. Defines the default data for a PersistentObject (or subclass thereof) within your game. PersistentObject.define() must only be called at initialization time, from story javascript or initialization passages.  The results of trying to use this function after the game has started are undefined.
  
-See the [[Tutorial]] for more details. +All PersistentObjects (and subclasses) must be defined using this method before they can be used within the game.  See the [[Tutorial]] for a better explanation of all of this.
- +
-  * //id//: the Persistence ID of the object being defined. +
-  * //objectClass//: the class of the object being defined.  PersistentObject or subclass thereof. +
-  * //defaults//: mapping of property names to data for the object's default data.  Records may only contain simple data types, arrays, and PersistentObjects (or subclasses thereof).  Non-persistent objects and symbols are not allowed. +
-  * //allowRedefine//: if true, the object may be redefined.  This is used internally and you probably shouldn't mess with it unless you are sure of what you are doing.+
  
 +  * **Type:** Static Function
 +  * **Arguments:**
 +    * //id//: the Persistence ID of the object being defined.
 +    * //objectClass//: the class of the object being defined.  PersistentObject or subclass thereof.
 +    * //defaults//: a mapping of property names to data for the object's default data.  Records may only contain simple data types, arrays, and PersistentObjects (or subclasses thereof).  Non-persistent objects and symbols are not allowed.
 +    * //allowRedefine//: if true, the object may be redefined.  This is used internally and you probably shouldn't mess with it unless you are sure of what you are doing.
   * **Returns:** An instantiated instance of the object that was defined.   * **Returns:** An instantiated instance of the object that was defined.
   * **Throws:** Error if the object is being redefined (and allowRedefine=false), if the previously defined object does not have a valid class associated with it, or if a defaults record contains a non-array object or symbol.   * **Throws:** Error if the object is being redefined (and allowRedefine=false), if the previously defined object does not have a valid class associated with it, or if a defaults record contains a non-array object or symbol.
- 
-All PersistentObjects (and subclasses) must be defined using this method before they can be used within the game.  See the [[Tutorial]] for a better explanation of all of this. 
  
 Example:<code> Example:<code>
Line 49: Line 49:
 The returned object is not guaranteed to be the same cached object every time, but they will evaluate as .equal() and for all intents and purposes are the "same" object, behaving identically, exposing the same properties, etc.  **So don't use strict equality when comparing objects.  Just don't, ok?** The returned object is not guaranteed to be the same cached object every time, but they will evaluate as .equal() and for all intents and purposes are the "same" object, behaving identically, exposing the same properties, etc.  **So don't use strict equality when comparing objects.  Just don't, ok?**
  
-  * id: the Persistence ID of the object being fetched. +  * **Type:** Static Function 
-  * forceClass: If set, overrides the class associated with the object ID and uses the given class instead.  This is used internally and you probably shouldn't mess with it unless you are sure of what you are doing.+  * **Arguments:** 
 +    * //id//: the Persistence ID of the object being fetched. 
 +    //forceClass//: If set, overrides the class associated with the object ID and uses the given class instead.  This is used internally and you probably shouldn't mess with it unless you are sure of what you are doing. 
 +  * **Returns:** An instantiated instance of the object defined with the given id. 
 +  * **Throws:** Error if the object does not have a valid class associated with it. 
 + 
 +Example:<code> 
 +FIXME 
 +</code>
  
-  * Returns: An instantiated instance of the object defined with the given id. 
-  * Throws: Error if the object does not have a valid class associated with it. 
  
-===== Constructor =====+===== Constructor( id ) =====
  
-//**ALERT!  MAKE NOTE!  ALERT!**//+//**ALERT!  TAKE NOTE!  ALERT!**//
  
 //**You should never instantiate a PersistentObject directly!  Instead, you must define it with PersistentObject.define(), and then either store the result somewhere or re-fetch it with PersistentObject.fetch() when you want to use it.**// //**You should never instantiate a PersistentObject directly!  Instead, you must define it with PersistentObject.define(), and then either store the result somewhere or re-fetch it with PersistentObject.fetch() when you want to use it.**//
Line 65: Line 71:
 //**Again, do not ever use "new" to instantiate a PersistentObject.  Instead, store the result of PersistentObject.define() somewhere and reference it when needed, or fetch the object by its 'id' with PersistentObject.fetch().**// //**Again, do not ever use "new" to instantiate a PersistentObject.  Instead, store the result of PersistentObject.define() somewhere and reference it when needed, or fetch the object by its 'id' with PersistentObject.fetch().**//
  
-===== Properties =====+===== Properties/Functions =====
  
 ==== .id ==== ==== .id ====
 This object's Persistence ID, as defined with PersistentObject.define(). This object's Persistence ID, as defined with PersistentObject.define().
  
-  * Type: String +  * **Type:** String 
-  * Automatic +  * **Automatic** 
-  * ReadOnly+  * **ReadOnly**
  
 ==== .parent ==== ==== .parent ====
 This object's parent.  For example, the parent of the object with the id "joe.inventory.contents" would be the object with the id "joe.inventory". This object's parent.  For example, the parent of the object with the id "joe.inventory.contents" would be the object with the id "joe.inventory".
  
-  * Type: PersistentObject or undefined (getter+  * **Type:** PersistentObject (or undefined if the object has no parent
-  * Automatic +  * **Automatic** 
-  * ReadOnly+  * **ReadOnly**
  
 ==== .name ==== ==== .name ====
 The display name of the object, without any article. For example: "Joe", "ancient relic", "pair of gloves". The display name of the object, without any article. For example: "Joe", "ancient relic", "pair of gloves".
  
-  * Type: String +  * **Type:** String
-  Required+
  
 ==== .nameIsProper ==== ==== .nameIsProper ====
 Set this field to True to suppress the printing of an article in the .aName, .theName, and generic versions of these fields. Useful for proper names, book titles, etc.  See the [[Tutorial]] for more information. Set this field to True to suppress the printing of an article in the .aName, .theName, and generic versions of these fields. Useful for proper names, book titles, etc.  See the [[Tutorial]] for more information.
  
-  * Type: Boolean +  * **Type:** Boolean
-  Optional+
  
 ==== .nameIrregularArticle ==== ==== .nameIrregularArticle ====
 Set this field to override the default article choice in .aName and generic versions of that field. Setting it back to undefined or null will return things to normal. Set this field to override the default article choice in .aName and generic versions of that field. Setting it back to undefined or null will return things to normal.
  
-  * Type: String +  * **Type:** String
-  Optional+
  
-==== .genericName === +==== .aName() ==== 
-This is the generic non-detailed name of the object, without any article.  This name is used when the item can be detected, but its exact details are unavailable.  For example, the genericName is used when an article of apparel is "showing an outline throughan article of thin but non-transparent apparel on a more outer layer.  It might also be used when interacting with objects in the dark, where you can feel what they are but cannot see specific details.+The display name of the object, with the correct article prepended. For example: "Joe", "an ancient relic", "a pair of gloves".
  
-  * Type: String +If the first character of the .name field is capitalized, the name will be treated as proper, and no article will be prepended. Ie. "Joe". Otherwise, if the first character of the .name field is a vowel, the "an" article will be prepended. Ie. "an ancient relic". Otherwise, the "a" article will be prepended. Ie. "a pair of gloves".
-  * Required+
  
-==== .genericNameIsProper ==== +These rules do not always workFor example, "an honorable man" or "a European swallow"In these cases, the .nameIsProper and .nameIrregularArticle fields may be used to manually specify the behavior of this field.
-Same as .nameIsProperbut operates on the genericName instead.+
  
-  * Type: Boolean +  * **Type:** Function 
-  * Optional+  * **Arguments:**  None 
 +  * **Returns:** String 
 +  * **Throws:** Nothing
  
-==== .genericNameIrregularArticle ==== +==== .AName() ==== 
-Same as .nameIrregularArticle, but operates on the genericName instead.+Same as .aName(), but with the first character capitalized.
  
-  * Type: String +  * **Type:** Function 
-  * Optional+  * **Arguments:**  None 
 +  * **Returns:** String 
 +  * **Throws:** Nothing
  
-==== .aName ==== +==== .theName() ==== 
-The display name of the object, with the correct article prepended. For example: "Joe", "an ancient relic", "pair of gloves".+The display name of the object, with the "the" prepended unless the object is proper. For example: "Joe", "the ancient relic", "the pair of gloves".
  
-If the first character of the .name field is capitalized, the name will be treated as proper, and no article will be prepended. Ie. "Joe"Otherwiseif the first character of the .name field is a vowel, the "an" article will be prepended. Ie. "an ancient relic". Otherwise, the "a" article will be prepended. Ie. "a pair of gloves".+These rules do not always workFor example"the European swallow"In this case, the .nameIsProper field may be used to manually specify the behavior of this field.
  
-These rules do not always work. For example, "an honorable man" or "a European swallow". In these cases, the .nameIsProper and .nameIrregularArticle fields may be used to manually specify the behavior of this field.+  * **Type:** Function 
 +  * **Arguments:**  None 
 +  * **Returns:** String 
 +  * **Throws:** Nothing
  
-  * Type: String (getterFIXME change to function so it can be overridden in story code more easily. +==== .TheName() ==== 
-  * Automatic+Identical to .theName(), but with the first character capitalized.
  
-==== .AName ==== +  * **Type:** Function 
-Same as .aName, but with the first character capitalized.+  * **Arguments:**  None 
 +  * **Returns:** String 
 +  * **Throws:** Nothing
  
-  * Type: String (getter) FIXME change to function so it can be overridden in story code more easily. +==== .genericName === 
-  * Automatic+This is the generic non-detailed name of the object, without any article.  This name is used when the item can be detected, but its exact details are unavailable.  For example, the genericName is used when an article of apparel is "printing through" an article of thin but non-transparent apparel on a more outer layer.  It might also be used when interacting with objects in the dark, where you can feel what they are but cannot see specific details.
  
-==== .aGenericName ==== +  * **Type:** String
-Same as .aName, but operates on the genericName instead.+
  
-  * Type: String (getter) FIXME change to function so it can be overridden in story code more easily+==== .genericNameIsProper ==== 
-  * Automatic+Same as .nameIsProper, but operates on the genericName instead.
  
-==== .AGenericName ==== +  * **Type:** Boolean
-Same as .AName, but operates on the genericName instead.+
  
-  * Type: String (getter) FIXME change to function so it can be overridden in story code more easily+==== .genericNameIrregularArticle ==== 
-  * Automatic+Same as .nameIrregularArticle, but operates on the genericName instead.
  
-==== .theName ==== +  * **Type:** String
-The display name of the object, with the "the" prepended unless the object is proper. For example"Joe", "the ancient relic", "the pair of gloves".+
  
-These rules do not always workFor example, "the European swallow"In this case, the .nameIsProper field may be used to manually specify the behavior of this field.+==== .aGenericName() ==== 
 +Same as .aName()but operates on the genericName instead.
  
-  * Type: String (getter) FIXME change to function so it can be overridden in story code more easily. +  * **Type:** Function 
-  * Automatic+  * **Arguments:**  None 
 +  * **Returns:** String 
 +  * **Throws:** Nothing
  
-==== .TheName ==== +==== .AGenericName() ==== 
-Identical to .theName, but with the first character capitalized.+Same as .AName(), but operates on the genericName instead.
  
-  * Type: String (getter) FIXME change to function so it can be overridden in story code more easily. +  * **Type:** Function 
-  * Automatic+  * **Arguments:**  None 
 +  * **Returns:** String 
 +  * **Throws:** Nothing
  
-==== .theGenericName ==== +==== .theGenericName() ==== 
-Same as .theName, but operates on the genericName instead.+Same as .theName(), but operates on the genericName instead.
  
-  * Type: String (getter) FIXME change to function so it can be overridden in story code more easily. +  * **Type:** Function 
-  * Automatic+  * **Arguments:**  None 
 +  * **Returns:** String 
 +  * **Throws:** Nothing
  
-==== .TheGenericName ==== +==== .TheGenericName() ==== 
-Same as .TheName, but operates on the genericName instead.+Same as .TheName(), but operates on the genericName instead.
  
-  * Type: String (getter) FIXME change to function so it can be overridden in story code more easily. +  * **Type:** Function 
-  * Automatic+  * **Arguments:**  None 
 +  * **Returns:** String 
 +  * **Throws:** Nothing
  
 ==== .image ==== ==== .image ====
-A detail image name for the object (used in object details displays, and in inventory thumbnails if no thumbnail is defined).+A detail image name for the object (used in object details displays, and in inventory thumbnails if no thumbnail is defined.
  
-FIXME Make this work with external images instead of just image passages. +  * **Type:** String
- +
-  * Type: String +
-  Required (if you use the Inventory and Apparel UIs)+
  
 ==== .thumbnail ==== ==== .thumbnail ====
-A thumbnail image name for the object (used in inventory displays).  If a thumbnail image is not definedcode should use the value of .image instead.+A thumbnail image name for the object (used in inventory displays).  By defaultit just returns the value of .image, but you can override it in subclasses or set it in PersistentObject.define() to use a thumbnail image that is different from the main detail image above.
  
-FIXME Make this work with external images instead of just image passages. +  * **Type:** Getter returning String
- +
-  * Type: String (getter) FIXME change to function so it can be overridden in story code more easily. +
-  Optional+
  
 ==== .description ==== ==== .description ====
 FIXME unimplemented FIXME unimplemented
  
-The name of a passage to display with the detail description of the object.  Links within can be used to manipulate the object.+The name of a passage to display with the detail description of the object. 
 + 
 +By default it will use some variant of the object id (FIXME what exactly?), but this can be overridden to make multiple objects use the same description passage.
  
   * Type: String   * Type: String
Line 212: Line 224:
 ==== .toJSON() ==== ==== .toJSON() ====
 Overridden to provide a reviveWrapper that grabs an instantiated copy of the object via PersistentObject.fetch(). Overridden to provide a reviveWrapper that grabs an instantiated copy of the object via PersistentObject.fetch().
- 
-==== .someProperty ==== 
-FIXME 
- 
-  * Type: type 
-  * Optional Required 
- 
-==== .someProperty ==== 
-FIXME 
- 
-  * Type: type 
-  * Optional Required 
- 
-==== .someProperty ==== 
-FIXME 
- 
-  * Type: type 
-  * Optional Required 
- 
-==== .someProperty ==== 
-FIXME 
- 
-  * Type: type 
-  * Optional Required 
- 
-==== .someProperty ==== 
-FIXME 
- 
-  * Type: type 
-  * Optional Required 
- 
-==== .someProperty ==== 
-FIXME 
- 
-  * Type: type 
-  * Optional Required 
- 
-==== .someProperty ==== 
-FIXME 
- 
-  * Type: type 
-  * Optional Required 
- 
  
smutbook/classes/persistence/persistentobject.1691529440.txt.gz · Last modified: 2023/08/08 14:17 by lee