25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

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