You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

283 lines
5.0 KiB

  1. const imageSize = require('image-size');
  2. const events = require('../misc/events');
  3. const fileLister = require('../misc/fileLister');
  4. const tos = require('./tos');
  5. const config = {
  6. logoPath: null,
  7. loginBgGeneratorPath: null,
  8. resourceList: [],
  9. textureList: [
  10. 'tiles',
  11. 'walls',
  12. 'mobs',
  13. 'bosses',
  14. 'animBigObjects',
  15. 'bigObjects',
  16. 'objects',
  17. 'characters',
  18. 'attacks',
  19. 'ui',
  20. 'auras',
  21. 'animChar',
  22. 'animMob',
  23. 'animBoss',
  24. 'white',
  25. 'ray'
  26. ],
  27. //Textures that are 24x24. The renderer needs to know this
  28. bigTextures: [
  29. 'animBigObjects',
  30. 'animBoss',
  31. 'bigObjects',
  32. 'bosses',
  33. 'auras'
  34. ],
  35. atlasTextureDimensions: {},
  36. atlasTextures: [
  37. 'tiles',
  38. 'walls',
  39. 'objects'
  40. ],
  41. spriteSizes: {
  42. 'images/tiles.png': 8,
  43. 'images/walls.png': 8,
  44. 'images/objects.png': 8,
  45. 'images/mobs.png': 8
  46. },
  47. blockingTileIndices: [
  48. 6, 7, 54, 55, 62, 63, 154, 189, 190, 192, 193, 194, 195, 196, 197
  49. ],
  50. tileOpacities: {
  51. default: {
  52. default: 0.4,
  53. max: 1
  54. },
  55. tiles: {
  56. default: 0.4,
  57. max: 0.55,
  58. 5: 0.7,
  59. 6: 0.9,
  60. 23: 0.9,
  61. 24: 0.9,
  62. 25: 0.9,
  63. 50: 1,
  64. 51: 1,
  65. 52: 1,
  66. 53: 0.7,
  67. 54: 0.5,
  68. 57: 1,
  69. 58: 1,
  70. 59: 1,
  71. 60: 0.9,
  72. 61: 0.9,
  73. 62: 0.75,
  74. 76: 0.9,
  75. 80: 1,
  76. 81: 1,
  77. 82: 1,
  78. 83: 1,
  79. 87: 1,
  80. 90: 1,
  81. 95: 1,
  82. 102: 0.9,
  83. 152: 0.9,
  84. 153: 1,
  85. 163: 0.9,
  86. //snow
  87. 176: 0.55,
  88. 184: 0.55,
  89. 185: 0.55
  90. },
  91. objects: {
  92. default: 0.9,
  93. 50: 1
  94. },
  95. walls: {
  96. default: 0.85,
  97. max: 1,
  98. 84: 1,
  99. 103: 0.9,
  100. 107: 0.9,
  101. 116: 1,
  102. 120: 0.9,
  103. 132: 0.9,
  104. 133: 0.9,
  105. 134: 0.85,
  106. 139: 1,
  107. 148: 1,
  108. 150: 0.85,
  109. 156: 1,
  110. 157: 1,
  111. 158: 1,
  112. 159: 1,
  113. 160: 0.9,
  114. 161: 1,
  115. 162: 1,
  116. 163: 1,
  117. 164: 0.8,
  118. 165: 1,
  119. 166: 0.95,
  120. 167: 1,
  121. 168: 1,
  122. 169: 1
  123. }
  124. },
  125. tilesNoFlip: {
  126. tiles: [
  127. //Stairs
  128. 171, 179
  129. ],
  130. walls: [
  131. //Ledges
  132. 156, 158, 162, 163, 167, 168,
  133. //Wall Sign
  134. 189,
  135. //Stone Ledges
  136. 195, 196, 197, 198, 199, 200, 201, 202, 203,
  137. //Ship Edges
  138. 204, 205, 206, 207, 214, 215, 220, 221, 222, 223,
  139. //Gray wall sides and corners
  140. 230, 231, 238, 239
  141. ],
  142. objects: [
  143. //Clotheslines
  144. 96, 101,
  145. //Table Sides
  146. 103, 110, 118, 126,
  147. //Wall-mounted plants
  148. 120, 122, 140,
  149. //Ship oars
  150. 140, 143,
  151. //Ship Cannons
  152. 141, 142,
  153. //Tent Pegs
  154. 168, 169
  155. ]
  156. },
  157. uiLoginList: [
  158. 'login'
  159. ],
  160. uiList: [
  161. 'inventory',
  162. 'equipment',
  163. 'hud',
  164. 'target',
  165. 'menu',
  166. 'spells',
  167. 'messages',
  168. 'online',
  169. 'mainMenu',
  170. 'context',
  171. 'party',
  172. 'help',
  173. 'dialogue',
  174. 'buffs',
  175. 'tooltips',
  176. 'tooltipInfo',
  177. 'tooltipItem',
  178. 'announcements',
  179. 'quests',
  180. 'events',
  181. 'progressBar',
  182. 'stash',
  183. 'talk',
  184. 'trade',
  185. 'overlay',
  186. 'death',
  187. 'leaderboard',
  188. 'reputation',
  189. 'wardrobe',
  190. 'passives',
  191. 'workbench',
  192. 'middleHud',
  193. 'options'
  194. ],
  195. contextMenuActions: {
  196. player: [],
  197. npc: []
  198. },
  199. clientComponents: [],
  200. sounds: {
  201. ui: []
  202. },
  203. tos
  204. };
  205. module.exports = {
  206. config,
  207. init: async function () {
  208. fileLister.getFolder('./clientComponents').forEach(f => {
  209. if (!f.endsWith('.js')) return;
  210. const type = f.split('.')[0];
  211. const path = 'server/clientComponents/' + f;
  212. config.clientComponents.push({
  213. type,
  214. path
  215. });
  216. });
  217. events.emit('onBeforeGetClientConfig', config);
  218. //Deprecated
  219. events.emit('onBeforeGetResourceList', config.resourceList);
  220. events.emit('onBeforeGetUiList', config.uiList);
  221. events.emit('onBeforeGetContextMenuActions', config.contextMenuActions);
  222. events.emit('onBeforeGetTermsOfService', config.tos);
  223. events.emit('onBeforeGetTextureList', config.textureList);
  224. await this.calculateAtlasTextureDimensions();
  225. },
  226. //The client needs to know this as well as the map loader
  227. calculateAtlasTextureDimensions: async function () {
  228. const { atlasTextures, atlasTextureDimensions } = config;
  229. for (const tex of atlasTextures) {
  230. if (atlasTextureDimensions[tex])
  231. return;
  232. const path = tex.includes('.png') ? `../${tex}` : `../client/images/${tex}.png`;
  233. const dimensions = await imageSize(path);
  234. delete dimensions.type;
  235. atlasTextureDimensions[tex] = dimensions;
  236. }
  237. },
  238. getTileIndexInAtlas: async function (spriteSheet, tileIndexInSource) {
  239. const { atlasTextures, atlasTextureDimensions } = config;
  240. //We need to perform this check because once mods start adding sheets to atlasTextures,
  241. // things get out of control. We need to fix this in the future as it will become screwy.
  242. if (Object.keys(atlasTextureDimensions).length !== atlasTextures)
  243. await this.calculateAtlasTextureDimensions();
  244. const indexOfSheet = atlasTextures.indexOf(spriteSheet);
  245. let tileCountBeforeSheet = 0;
  246. for (let i = 0; i < indexOfSheet; i++) {
  247. const sheet = atlasTextures[i];
  248. const { width, height } = atlasTextureDimensions[sheet];
  249. tileCountBeforeSheet += ((width / 8) * (height / 8));
  250. }
  251. //Tile index 0 is 'no tile' in map files so we need to increment by 1
  252. const result = tileCountBeforeSheet + tileIndexInSource + 1;
  253. return result;
  254. },
  255. //Used to send to clients
  256. getClientConfig: function (msg) {
  257. msg.callback(config);
  258. }
  259. };