Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

77 lignes
1.4 KiB

  1. define([
  2. 'js/system/globals'
  3. ], function (
  4. globals
  5. ) {
  6. let noFlipTiles = null;
  7. let tileOpacities = null;
  8. return {
  9. initMap: function (msg) {
  10. noFlipTiles = msg.noFlipTiles;
  11. tileOpacities = msg.tileOpacities;
  12. },
  13. getSheetNum: function (tile) {
  14. if (tile < 224)
  15. return 0;
  16. else if (tile < 480)
  17. return 1;
  18. return 2;
  19. },
  20. getSheetName: function (tile) {
  21. const { clientConfig: { atlasTextures } } = globals;
  22. const sheetNum = this.getSheetNum(tile);
  23. const sheetName = atlasTextures[sheetNum];
  24. return sheetName;
  25. },
  26. getOffsetAndSheet: function (tile) {
  27. const { clientConfig: { atlasTextureDimensions, atlasTextures } } = globals;
  28. let offset = 0;
  29. let sheetName = null;
  30. let aLen = atlasTextures.length;
  31. for (let i = 0; i < aLen; i++) {
  32. sheetName = atlasTextures[i];
  33. const dimensions = atlasTextureDimensions[sheetName];
  34. const spriteCount = dimensions.w * dimensions.h;
  35. if (offset + spriteCount > tile)
  36. break;
  37. offset += spriteCount;
  38. }
  39. return {
  40. offset,
  41. sheetName
  42. };
  43. },
  44. map: function (tile) {
  45. if (tileOpacities[tile] === undefined)
  46. return 1;
  47. const { max, opacity } = tileOpacities[tile];
  48. let alpha = opacity;
  49. if (max !== undefined) {
  50. alpha = alpha + (Math.random() * (alpha * 0.2));
  51. alpha = Math.min(1, alpha);
  52. }
  53. return alpha;
  54. },
  55. canFlip: function (tile) {
  56. return !noFlipTiles.includes(tile + 1);
  57. }
  58. };
  59. });