ContentType.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. defaultValue : boolean;
  7. description : Say | string;
  8. currentValueDescription? : (c : ContentType) => Say | string;
  9. /**
  10. * Use sparingly. Content-Types that shouldn't be allowed to change are those that either:
  11. * - 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.
  12. * - 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.
  13. */
  14. changeable? : boolean;
  15. }
  16. class ContentType extends StoredMemory<boolean> {
  17. private description : Say;
  18. private valueDescription : (c : ContentType) => Say | string = () => { return new Say (JSON.stringify(this.getValue())); };
  19. private changeable : boolean = true;
  20. private static memoryPrefix = "ct_";
  21. public constructor (options : ContentTypeOptions) {
  22. super(ContentType.memoryPrefix + options.id, options.defaultValue);
  23. this.description = options.description instanceof Say ? options.description : new Say(options.description);
  24. this.valueDescription = options.currentValueDescription == undefined ? this.valueDescription : options.currentValueDescription;
  25. if (options.changeable == false) {
  26. this.storeValue(options.defaultValue); // prevent localStorage alterations from affecting something that can't be changed
  27. this.changeable = false;
  28. }
  29. ContentHandler.registerContentType(this);
  30. }
  31. public getDescription () {
  32. return this.description;
  33. }
  34. public getValueDescription () {
  35. let desc = this.valueDescription(this);
  36. if (desc instanceof Say) {
  37. return desc;
  38. } else {
  39. return new Say(desc);
  40. }
  41. }
  42. public toggle () {
  43. if (this.changeable) {
  44. this.storeValue(!this.getValue());
  45. }
  46. }
  47. public isAllowed() {
  48. return this.getValue();
  49. }
  50. public static MM = new ContentType({
  51. 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
  52. description : "Homosexual (M/M) sexual events",
  53. id : "MM",
  54. defaultValue : true
  55. });
  56. public static FF = new ContentType({
  57. 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
  58. description : "Homosexual (F/F) sexual events",
  59. id : "FF",
  60. defaultValue : true
  61. });
  62. public static MF = new ContentType({
  63. 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
  64. description : "Heterosexual (M/F) sexual events",
  65. id : "MF",
  66. defaultValue : true
  67. });
  68. public static Beast = new ContentType({
  69. changeable : true,
  70. description : "Sexual events with either monsters or magical beasts. MM/MF/FF take precedence over this one if blocked. Sufficiently human creatures do not get counted into this.",
  71. id : "Beast",
  72. defaultValue : true
  73. });
  74. public static Scat = new ContentType({
  75. changeable : false,
  76. description : "Scatologic sexual events",
  77. id : "Scat",
  78. defaultValue : false // There is no intention of ever adding these
  79. });
  80. public static Pee = new ContentType({
  81. changeable : false,
  82. description : "Sexual events with urine",
  83. id : "Urophilia",
  84. defaultValue : false // There is no intention of ever adding these
  85. });
  86. }