Browse Source

feat[#1722]: Made blocking tile indices moddable

tags/v0.9.0^2
Shaun 3 years ago
parent
commit
887b031e51
4 changed files with 41 additions and 17 deletions
  1. +2
    -2
      src/client/js/rendering/renderer.js
  2. +1
    -5
      src/client/js/rendering/tileOpacity.js
  3. +35
    -4
      src/server/config/clientConfig.js
  4. +3
    -6
      src/server/world/map.js

+ 2
- 2
src/client/js/rendering/renderer.js View File

@@ -126,7 +126,7 @@ define([
},

buildSpritesTexture: function () {
const { clientConfig: { atlasTextures } } = globals;
const { clientConfig: { atlasTextureDimensions, atlasTextures } } = globals;

let container = new pixi.Container();

@@ -139,7 +139,7 @@ define([
tile.x = 0;
tile.y = totalHeight;

tileOpacity.atlasTextureDimensions[t] = {
atlasTextureDimensions[t] = {
w: texture.width / 8,
h: texture.height / 8
};


+ 1
- 5
src/client/js/rendering/tileOpacity.js View File

@@ -4,9 +4,6 @@ define([
globals
) {
return {
//Set by renderer
atlasTextureDimensions: {},

getSheetNum: function (tile) {
if (tile < 224)
return 0;
@@ -25,8 +22,7 @@ define([
},

getOffsetAndSheet: function (tile) {
const { clientConfig: { atlasTextures } } = globals;
const { atlasTextureDimensions } = this;
const { clientConfig: { atlasTextureDimensions, atlasTextures } } = globals;

let offset = 0;
let sheetName = null;


+ 35
- 4
src/server/config/clientConfig.js View File

@@ -33,11 +33,15 @@ const config = {
'bosses',
'auras'
],
atlasTextureDimensions: {},
atlasTextures: [
'tiles',
'walls',
'objects'
],
blockingTileIndices: [
6, 7, 54, 55, 62, 63, 154, 189, 190, 192, 193, 194, 195, 196, 197
],
tileOpacities: {
default: {
default: 0.4,
@@ -196,8 +200,6 @@ const config = {
module.exports = {
config,

atlasTextureDimensions: {},

init: async function () {
events.emit('onBeforeGetClientConfig', config);

@@ -213,14 +215,43 @@ module.exports = {

//The client needs to know this as well as the map loader
calculateAtlasTextureDimensions: async function () {
for (const tex of config.atlasTextures) {
const { atlasTextures, atlasTextureDimensions } = config;

for (const tex of atlasTextures) {
if (atlasTextureDimensions[tex])
return;

const path = tex.includes('.png') ? `../${tex}` : `../client/images/${tex}.png`;
const dimensions = await imageSize(path);

delete dimensions.type;

this.atlasTextureDimensions[tex] = dimensions;
atlasTextureDimensions[tex] = dimensions;
}
},

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

//We need to perform this check because once mods start adding sheets to atlasTextures,
// things get out of control. We need to fix this in the future as it will become screwy.
if (Object.keys(atlasTextureDimensions).length !== atlasTextures)
await this.calculateAtlasTextureDimensions();

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));
}

const result = tileCountBeforeSheet + tileIndexInSource;

return result;
},

//Used to send to clients


+ 3
- 6
src/server/world/map.js View File

@@ -300,7 +300,7 @@ module.exports = {
},

getOffsetCellPos: function (sheetName, cell) {
const { atlasTextureDimensions, config: { atlasTextures } } = clientConfig;
const { config: { atlasTextureDimensions, atlasTextures } } = clientConfig;
const indexInAtlas = atlasTextures.indexOf(sheetName);

let offset = 0;
@@ -378,11 +378,8 @@ module.exports = {

if (layerName.indexOf('walls') > -1)
this.collisionMap[x][y] = 1;
else if (layerName === 'tiles' && sheetName === 'tiles') {
//Check for water and water-like tiles
if ([6, 7, 54, 55, 62, 63, 154, 189, 190, 192, 193, 194, 195, 196, 197].includes(offsetCell))
this.collisionMap[x][y] = 1;
}
else if (clientConfig.config.blockingTileIndices.includes(offsetCell))
this.collisionMap[x][y] = 1;
},

object: function (layerName, cell) {


Loading…
Cancel
Save