Browse Source

Added clientConfig.getTileIndexInAtlasSync for use by mods when we know that the sprite atlas has already fully loaded

tags/v0.14.0^2
Shaun 3 months ago
parent
commit
36248f84ea
1 changed files with 20 additions and 0 deletions
  1. +20
    -0
      src/server/config/clientConfig.js

+ 20
- 0
src/server/config/clientConfig.js View File

@@ -283,6 +283,26 @@ module.exports = {
return result;
},

getTileIndexInAtlasSync: function (spriteSheet, tileIndexInSource) {
const { atlasTextures, atlasTextureDimensions } = config;

const indexOfSheet = atlasTextures.indexOf(spriteSheet);

let tileCountBeforeSheet = 0;

for (let i = 0; i < indexOfSheet; i++) {
const sheet = atlasTextures[i];
const { width, height } = atlasTextureDimensions[sheet];

tileCountBeforeSheet += ((width / 8) * (height / 8));
}

//Tile index 0 is 'no tile' in map files so we need to increment by 1
const result = tileCountBeforeSheet + tileIndexInSource + 1;

return result;
},

//Used to send to clients
getClientConfig: function (msg) {
msg.callback(config);


Loading…
Cancel
Save