settings.d.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. export interface SettingDefinition {
  2. /**
  3. * Label to use for the control.
  4. */
  5. label: string;
  6. /**
  7. * Description explaining the control in greater detail.
  8. */
  9. desc?: string | undefined;
  10. /**
  11. * The function to call during initialization.
  12. */
  13. onInit?: (() => void) | undefined;
  14. /**
  15. * The function to call when the control's state is changed.
  16. */
  17. onChange?: (() => void) | undefined;
  18. }
  19. export interface ToggleDefinition extends SettingDefinition {
  20. /**
  21. * The default value for the setting and default state of the control. Leaving it undefined means to use false as the default.
  22. */
  23. default?: boolean | undefined;
  24. }
  25. export interface ListDefinition<T> extends SettingDefinition {
  26. /**
  27. * The array of items.
  28. */
  29. list: T[];
  30. /**
  31. * Description explaining the control in greater detail.
  32. */
  33. desc?: string | undefined;
  34. /**
  35. * The default value for the setting and default state of the control. It should have the same value as one of the members of
  36. * the list array. Leaving it undefined means to use the first array member as the default.
  37. */
  38. default?: T | undefined;
  39. }
  40. export interface RangeDefinition extends SettingDefinition {
  41. /**
  42. * The minimum value.
  43. */
  44. min: number;
  45. /**
  46. * The maximum value.
  47. */
  48. max: number;
  49. /**
  50. * Limits the increments to which the value may be set. It must be evenly divisible into the full range — i.e., max - min.
  51. */
  52. step: number;
  53. /**
  54. * The default value for the setting and default state of the control. Leaving it undefined means to use the value of max as the default.
  55. */
  56. default?: number | undefined;
  57. }
  58. export interface SettingsAPI {
  59. /**
  60. * Adds a header to the Settings dialog.
  61. * @param name Name of the header.
  62. * @param desc Description explaining the header in greater detail.
  63. * @since 2.7.1
  64. * @example
  65. * // Setting up a basic header
  66. * Setting.addHeader("Content Settings");
  67. *
  68. * // Setting up a header w/ a description
  69. * Setting.addHeader("Content Settings", "Settings controlling what content is made available in the game.");
  70. */
  71. addHeader(name: string, desc?: string): void;
  72. /**
  73. * Adds the named property to the settings object and a toggle control for it to the Settings dialog.
  74. * @param name Name of the settings property to add, which the control will manage.
  75. * @param definition Definition of the control.
  76. * @since 2.26.0
  77. * @example
  78. * // Basic toggle setting
  79. * // Setting up a basic toggle control for the settings property 'mature'
  80. * Setting.addToggle("mature", {
  81. * label : "Content for mature audiences?"
  82. * }); // default value not defined, so false is used
  83. * @example
  84. * // Toggle that adds/removes a CSS class
  85. * // Setting up a toggle control for the settings property 'widescreen' w/ callbacks
  86. * var settingWidescreenHandler = function () {
  87. * if (settings.widescreen) { // is true
  88. * $("html").addClass("widescreen");
  89. * }
  90. * else { // is false
  91. * $("html").removeClass("widescreen");
  92. * }
  93. * };
  94. *
  95. * Setting.addToggle("widescreen", {
  96. * label : "Allow the story to use the full width of your browser window?",
  97. * default : false,
  98. * onInit : settingWidescreenHandler,
  99. * onChange : settingWidescreenHandler
  100. * });
  101. */
  102. addToggle(name: string, definition: ToggleDefinition): void;
  103. /**
  104. * Adds the named property to the settings object and a list control for it to the Settings dialog.
  105. * @param name Name of the settings property to add, which the control will manage.
  106. * @param definition Definition of the control.
  107. * @since 2.0.0 Basic syntax.
  108. * @since 2.26.0 Added desc property to definition object.
  109. * @example
  110. * // Setting up a basic list control for the settings property 'difficulty'
  111. * Setting.addList("difficulty", {
  112. * label : "Choose a difficulty level.",
  113. * list : ["Easy", "Normal", "Hard", "INSANE"],
  114. * default : "Normal"
  115. * });
  116. * @example
  117. * // Setting up a list control for the settings property 'theme' w/ callbacks
  118. * var settingThemeNames = ["(none)", "Bright Lights", "Charcoal", "Midnight", "Tinsel City"];
  119. * var settingThemeHandler = function () {
  120. * // cache the jQuery-wrapped <html> element
  121. * var $html = $("html");
  122. * // remove any existing theme class
  123. * $html.removeClass("theme-bright-lights theme-charcoal theme-midnight theme-tinsel-city");
  124. * // switch on the theme name to add the requested theme class
  125. * switch (settings.theme) {
  126. * case "Bright Lights":
  127. * $html.addClass("theme-bright-lights");
  128. * break;
  129. * case "Charcoal":
  130. * $html.addClass("theme-charcoal");
  131. * break;
  132. * case "Midnight":
  133. * $html.addClass("theme-midnight");
  134. * break;
  135. * case "Tinsel City":
  136. * $html.addClass("theme-tinsel-city");
  137. * break;
  138. * }
  139. * };
  140. * Setting.addList("theme", {
  141. * label : "Choose a theme.",
  142. * list : settingThemeNames,
  143. * onInit : settingThemeHandler,
  144. * onChange : settingThemeHandler
  145. * }); // default value not defined, so the first array member "(none)" is used
  146. */
  147. // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
  148. addList<T>(name: string, definition: ListDefinition<T>): void;
  149. /**
  150. * Adds the named property to the settings object and a range control for it to the Settings dialog.
  151. * @param name Name of the settings property to add, which the control will manage.
  152. * @param definition Definition of the control.
  153. * @since 2.26.0
  154. * @example
  155. * // Setting up a volume control for the settings property 'masterVolume' w/ callback
  156. * Setting.addRange("masterVolume", {
  157. * label : "Master volume.",
  158. * min : 0,
  159. * max : 10,
  160. * step : 1,
  161. * onChange : function () {
  162. * SimpleAudio.volume(settings.masterVolume / 10);
  163. * }
  164. * }); // default value not defined, so max value (10) is used
  165. */
  166. addRange(name: string, definition: RangeDefinition): void;
  167. /**
  168. * Loads the settings from storage.
  169. *
  170. * **NOTE**: The API automatically calls this method at startup, so you should never need to call this method manually.
  171. * @since 2.0.0
  172. */
  173. load(): void;
  174. /**
  175. * Resets the setting with the given name to its default value. If no name is given, resets all settings.
  176. * @param name Name of the settings object property to reset.
  177. * @since 2.0.0
  178. * @example
  179. * // Reset the setting 'difficulty'
  180. * Setting.reset("difficulty");
  181. *
  182. * // Reset all settings
  183. * Setting.reset();
  184. */
  185. reset(name?: string): void;
  186. /**
  187. * Saves the settings to storage.
  188. *
  189. * **NOTE**: The controls of the Settings dialog automatically call this method when settings are changed,
  190. * so you should normally never need to call this method manually. Only when manually modifying the values
  191. * of settings object properties, outside of the controls, would you need to call this method.
  192. * @since 2.0.0
  193. */
  194. save(): void;
  195. }
  196. export {};