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.
 
 
 

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