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.
 
 
 

80 line
1.7 KiB

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