No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

158 líneas
4.3 KiB

  1. //Imports
  2. const objects = require('../../../objects/objects');
  3. const spawners = require('./../../spawners');
  4. const resourceSpawner = require('../../resourceSpawner');
  5. const mapObjects = require('../mapObjects');
  6. const getObjectifiedProperties = require('../getObjectifiedProperties');
  7. const spriteBuilder = require('../../spriteBuilder/index');
  8. //Helpers
  9. const buildRoom = (mapModule, blueprint) => {
  10. if (blueprint.properties.exit) {
  11. const room = mapModule.rooms.find(r => {
  12. return (!(
  13. (blueprint.x + blueprint.width < r.x) ||
  14. (blueprint.y + blueprint.height < r.y) ||
  15. (blueprint.x >= r.x + r.width) ||
  16. (blueprint.y >= r.y + r.height)
  17. ));
  18. });
  19. room.exits.push(blueprint);
  20. } else if (blueprint.properties.resource)
  21. resourceSpawner.register(blueprint.properties.resource, blueprint);
  22. else {
  23. blueprint.exits = [];
  24. blueprint.objects = [];
  25. mapModule.rooms.push(blueprint);
  26. }
  27. };
  28. const buildHiddenRoom = (mapModule, blueprint) => {
  29. const { mapFile } = mapModule;
  30. const { cell } = blueprint;
  31. blueprint.fog = (cell.properties || {}).fog;
  32. blueprint.interior = (cell.properties || {}).interior;
  33. blueprint.discoverable = (cell.properties || {}).discoverable;
  34. blueprint.layer = ~~((cell.properties || {}).layer || 0);
  35. if (!mapFile.properties.isRandom)
  36. mapModule.hiddenRooms.push(blueprint);
  37. else {
  38. const room = mapModule.rooms.find(r => {
  39. return !(
  40. blueprint.x < r.x ||
  41. blueprint.y < r.y ||
  42. blueprint.x >= r.x + r.width ||
  43. blueprint.y >= r.y + r.height
  44. );
  45. });
  46. room.objects.push(blueprint);
  47. }
  48. };
  49. const buildRegularObject = (mapModule, blueprint) => {
  50. const { mapFile } = mapModule;
  51. if (!mapFile.properties.isRandom)
  52. spawners.register(blueprint, blueprint.spawnCd || mapFile.properties.spawnCd);
  53. else {
  54. const room = mapModule.rooms.find(r => {
  55. return !(
  56. blueprint.x < r.x ||
  57. blueprint.y < r.y ||
  58. blueprint.x >= r.x + r.width ||
  59. blueprint.y >= r.y + r.height
  60. );
  61. });
  62. room.objects.push(blueprint);
  63. }
  64. };
  65. const buildClientObject = (mapModule, blueprint) => {
  66. const { mapScale } = mapModule;
  67. const { cell } = blueprint;
  68. if ((cell.width) && (!cell.polyline)) {
  69. blueprint.width = cell.width / mapScale;
  70. blueprint.height = cell.height / mapScale;
  71. }
  72. const obj = objects.buildObjects([blueprint], true).getSimple(true);
  73. mapModule.objBlueprints.push(obj);
  74. };
  75. //Builder
  76. const buildObject = (mapModule, layerName, cell) => {
  77. const { mapScale } = mapModule;
  78. cell.properties = getObjectifiedProperties(cell.properties);
  79. cell.polyline = cell.polyline || cell.polygon;
  80. const x = cell.x / mapScale;
  81. const y = (cell.y / mapScale) - 1;
  82. const clientObj = (layerName === 'clientObjects');
  83. const cellInfo = mapModule.getCellInfo(cell.gid, x, y, layerName);
  84. let name = (cell.name || '');
  85. let objZoneName = name;
  86. if (name.indexOf('|') > -1) {
  87. const split = name.split('|');
  88. name = split[0];
  89. objZoneName = split[1];
  90. }
  91. const blueprint = {
  92. id: cell.properties.id,
  93. clientObj: clientObj,
  94. sheetName: cell.isDefined('sheetName') ? cell.sheetName : cellInfo.sheetName,
  95. cell: cell.isDefined('cell') ? cell.cell : cellInfo.cell - 1,
  96. x,
  97. y,
  98. name: name,
  99. properties: cell.properties || {},
  100. layerName: layerName
  101. };
  102. if (objZoneName !== name)
  103. blueprint.objZoneName = objZoneName;
  104. if (mapModule.zone) {
  105. if ((mapModule.zone.objects) && (mapModule.zone.objects[objZoneName.toLowerCase()]))
  106. extend(blueprint, mapModule.zone.objects[objZoneName.toLowerCase()]);
  107. else if ((mapModule.zone.objects) && (mapModule.zone.mobs[objZoneName.toLowerCase()]))
  108. extend(blueprint, mapModule.zone.mobs[objZoneName.toLowerCase()]);
  109. }
  110. if (blueprint.blocking)
  111. mapModule.collisionMap[blueprint.x][blueprint.y] = 1;
  112. if ((blueprint.properties.cpnNotice) || (blueprint.properties.cpnLightPatch) || (layerName === 'rooms') || (layerName === 'hiddenRooms')) {
  113. blueprint.y++;
  114. blueprint.width = cell.width / mapScale;
  115. blueprint.height = cell.height / mapScale;
  116. } else if (cell.width === 24)
  117. blueprint.x++;
  118. if (cell.polyline)
  119. mapObjects.polyline(mapModule.size, blueprint, cell, mapScale);
  120. if (layerName === 'rooms')
  121. buildRoom(mapModule, blueprint);
  122. else if (layerName === 'hiddenRooms')
  123. buildHiddenRoom(mapModule, blueprint);
  124. else if (!clientObj)
  125. buildRegularObject(mapModule, blueprint);
  126. else
  127. buildClientObject(mapModule, blueprint);
  128. };
  129. module.exports = buildObject;