ContentType.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /// <reference path="StoredMemory.ts" />
  2. /// <reference path="../../Elements/Classes/Say.ts" />
  3. /// <reference path="../Modules/ContentHandler.ts" />
  4. interface ContentTypeOptions {
  5. id : string;
  6. name : string;
  7. defaultValue : boolean;
  8. description : Say | string;
  9. currentValueDescription? : (c : ContentType) => Say | string;
  10. /**
  11. * Use sparingly. Content-Types that shouldn't be allowed to change are those that either:
  12. * - Fundamental to the game in some way. Most of these will only remain stuck until the game has enough content to make do without it.
  13. * - Something that's only a negative signal: signalizing that this content will not appear during development/gameplay at all, letting players know it isn't available and probably won't be.
  14. */
  15. changeable? : boolean;
  16. }
  17. class ContentType extends StoredMemory<boolean> {
  18. public name : string;
  19. private description : Say;
  20. private valueDescription : (c : ContentType) => Say | string = () => { return new Say (JSON.stringify(this.getValue())); };
  21. private changeable : boolean = true;
  22. private static memoryPrefix = "ct_";
  23. public constructor (options : ContentTypeOptions) {
  24. super(ContentType.memoryPrefix + options.id, options.defaultValue);
  25. this.description = options.description instanceof Say ? options.description : new Say(options.description);
  26. this.valueDescription = options.currentValueDescription == undefined ? this.valueDescription : options.currentValueDescription;
  27. if (options.changeable == false) {
  28. this.storeValue(options.defaultValue); // prevent localStorage alterations from affecting something that can't be changed
  29. this.changeable = false;
  30. }
  31. this.name = options.name;
  32. ContentHandler.registerContentType(this);
  33. }
  34. public getDescription () {
  35. return this.description;
  36. }
  37. public getName () {
  38. return this.name;
  39. }
  40. public getValueDescription () {
  41. let desc = this.valueDescription(this);
  42. if (desc instanceof Say) {
  43. return desc;
  44. } else {
  45. return new Say(desc);
  46. }
  47. }
  48. public toggle () {
  49. if (this.changeable) {
  50. this.storeValue(!this.getValue());
  51. }
  52. }
  53. public isAllowed() {
  54. return this.getValue();
  55. }
  56. public isChangeable () {
  57. return this.changeable;
  58. }
  59. public static MM = new ContentType({
  60. changeable : false, // There will be too little content at first for us to block part of it for no good reason, maybe at some point
  61. name: "Male-Male",
  62. description : "Homosexual (M/M) sexual encounters.",
  63. id : "MM",
  64. defaultValue : true
  65. });
  66. public static FF = new ContentType({
  67. changeable : false, // There will be too little content at first for us to block part of it for no good reason, maybe at some point
  68. description : "Homosexual (F/F) sexual events.",
  69. name : "Female-Female",
  70. id : "FF",
  71. defaultValue : true
  72. });
  73. public static MF = new ContentType({
  74. changeable : false, // There will be too little content at first for us to block part of it for no good reason, maybe at some point
  75. name : "Male-Female",
  76. description : "Heterosexual (M/F) sexual events.",
  77. id : "MF",
  78. defaultValue : true
  79. });
  80. public static Beast = new ContentType({
  81. changeable : true,
  82. description : "Sexual events with either monsters or magical beasts. MM/MF/FF take precedence over this one if blocked. Sufficiently human creatures (like Orcs and even Ogres) do not get counted into this, furry ones (Minotaurs) do..",
  83. id : "Beast",
  84. name : "Beast mode",
  85. defaultValue : true
  86. });
  87. public static Ravishment = new ContentType({
  88. changeable : true,
  89. description : "Allows sexual events to be initiated and continued by NPCs regardless of what the player says or does. Without this, sexual events can only be initiated by the player.",
  90. id : "Ravish",
  91. name : "Ravishment",
  92. defaultValue : true
  93. });
  94. }