1
1

SavedEvent.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /// <reference path="StoredVariable.ts" />
  2. interface SavedEventOptions<T> extends StoredVariableOptions<T> {
  3. description : string;
  4. valueDescription : (value : T) => string;
  5. }
  6. class SavedEvent<T> extends StoredVariable<T> {
  7. private description : string;
  8. public getValueDescription : (value : T) => string;
  9. public constructor (options : SavedEventOptions<T>) {
  10. super(options);
  11. this.description = options.description;
  12. this.getValueDescription = options.valueDescription;
  13. }
  14. public getDescription () {
  15. return this.description;
  16. }
  17. }
  18. //Example
  19. let EVENT_ORC_CHIEF_KILLED = new SavedEvent<boolean>(
  20. <SavedEventOptions<boolean>> {
  21. id: "EVENT_ORC_CHIEF_KILLED",
  22. description: "Describer whether the orc chief is alive or dead.",
  23. value: false,
  24. valueDescription: (value: boolean) => {
  25. if (EVENT_ORC_CHIEF_KILLED.value) {
  26. return "The orc chief has been killed.";
  27. } else {
  28. return "The orc chief is alive."
  29. }
  30. }
  31. }
  32. );