25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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