@@ -126,10 +126,12 @@ define([ | |||
}, | |||
buildSpritesTexture: function () { | |||
const { clientConfig: { atlasTextures } } = globals; | |||
let container = new pixi.Container(); | |||
let totalHeight = 0; | |||
['tiles', 'walls', 'objects'].forEach(t => { | |||
atlasTextures.forEach(t => { | |||
let texture = this.textures[t]; | |||
let tile = new pixi.Sprite(new pixi.Texture(texture)); | |||
tile.width = texture.width; | |||
@@ -137,6 +139,11 @@ define([ | |||
tile.x = 0; | |||
tile.y = totalHeight; | |||
tileOpacity.atlasTextureDimensions[t] = { | |||
w: texture.width / 8, | |||
h: texture.height / 8 | |||
}; | |||
container.addChild(tile); | |||
totalHeight += tile.height; | |||
@@ -1,80 +1,11 @@ | |||
define([ | |||
'js/system/globals' | |||
], function ( | |||
globals | |||
) { | |||
return { | |||
sheetHeight: 20, | |||
tiles: { | |||
default: 0.4, | |||
max: 0.55, | |||
5: 0.7, | |||
6: 0.9, | |||
23: 0.9, | |||
24: 0.9, | |||
25: 0.9, | |||
50: 1, | |||
51: 1, | |||
52: 1, | |||
53: 0.7, | |||
54: 0.5, | |||
57: 1, | |||
58: 1, | |||
59: 1, | |||
60: 0.9, | |||
61: 0.9, | |||
62: 0.75, | |||
76: 0.9, | |||
80: 1, | |||
81: 1, | |||
82: 1, | |||
83: 1, | |||
87: 1, | |||
90: 1, | |||
95: 1, | |||
102: 0.9, | |||
152: 0.9, | |||
153: 1, | |||
163: 0.9, | |||
//snow | |||
176: 0.55, | |||
184: 0.55, | |||
185: 0.55 | |||
}, | |||
objects: { | |||
default: 0.9, | |||
50: 1 | |||
}, | |||
walls: { | |||
default: 0.85, | |||
max: 1, | |||
84: 1, | |||
103: 0.9, | |||
107: 0.9, | |||
116: 1, | |||
120: 0.9, | |||
132: 0.9, | |||
133: 0.9, | |||
134: 0.85, | |||
139: 1, | |||
148: 1, | |||
150: 0.85, | |||
156: 1, | |||
157: 1, | |||
158: 1, | |||
159: 1, | |||
160: 0.9, | |||
161: 1, | |||
162: 1, | |||
163: 1, | |||
164: 0.8, | |||
165: 1, | |||
166: 0.95, | |||
167: 1, | |||
168: 1, | |||
169: 1 | |||
}, | |||
//Set by renderer | |||
atlasTextureDimensions: {}, | |||
tilesNoFlip: [ | |||
//Stairs | |||
@@ -114,22 +45,31 @@ define([ | |||
}, | |||
map: function (tile) { | |||
let sheetNum; | |||
const { clientConfig: { atlasTextures, tileOpacities } } = globals; | |||
const { atlasTextureDimensions } = this; | |||
if (tile < 224) | |||
sheetNum = 0; | |||
else if (tile < 480) { | |||
tile -= 224; | |||
sheetNum = 1; | |||
} else { | |||
tile -= 480; | |||
sheetNum = 2; | |||
let offset = 0; | |||
let sheetName = null; | |||
let aLen = atlasTextures.length; | |||
for (let i = 0; i < aLen; i++) { | |||
sheetName = atlasTextures[i]; | |||
const dimensions = atlasTextureDimensions[sheetName]; | |||
const spriteCount = dimensions.w * dimensions.h; | |||
if (offset + spriteCount > tile) | |||
break; | |||
offset += spriteCount; | |||
} | |||
let tilesheet = [this.tiles, this.walls, this.objects][sheetNum]; | |||
tile -= offset; | |||
const opacityConfig = tileOpacities[sheetName] || tileOpacities.default; | |||
let alpha = (tilesheet[tile] || tilesheet.default); | |||
if (tilesheet.max !== null) { | |||
let alpha = (opacityConfig[tile] || opacityConfig.default); | |||
if (opacityConfig.max !== null) { | |||
alpha = alpha + (Math.random() * (alpha * 0.2)); | |||
alpha = Math.min(1, alpha); | |||
} | |||
@@ -1,3 +1,5 @@ | |||
const imageSize = require('image-size'); | |||
const events = require('../misc/events'); | |||
const tos = require('./tos'); | |||
@@ -36,6 +38,81 @@ const config = { | |||
'walls', | |||
'objects' | |||
], | |||
tileOpacities: { | |||
default: { | |||
default: 0.4, | |||
max: 1 | |||
}, | |||
tiles: { | |||
default: 0.4, | |||
max: 0.55, | |||
5: 0.7, | |||
6: 0.9, | |||
23: 0.9, | |||
24: 0.9, | |||
25: 0.9, | |||
50: 1, | |||
51: 1, | |||
52: 1, | |||
53: 0.7, | |||
54: 0.5, | |||
57: 1, | |||
58: 1, | |||
59: 1, | |||
60: 0.9, | |||
61: 0.9, | |||
62: 0.75, | |||
76: 0.9, | |||
80: 1, | |||
81: 1, | |||
82: 1, | |||
83: 1, | |||
87: 1, | |||
90: 1, | |||
95: 1, | |||
102: 0.9, | |||
152: 0.9, | |||
153: 1, | |||
163: 0.9, | |||
//snow | |||
176: 0.55, | |||
184: 0.55, | |||
185: 0.55 | |||
}, | |||
objects: { | |||
default: 0.9, | |||
50: 1 | |||
}, | |||
walls: { | |||
default: 0.85, | |||
max: 1, | |||
84: 1, | |||
103: 0.9, | |||
107: 0.9, | |||
116: 1, | |||
120: 0.9, | |||
132: 0.9, | |||
133: 0.9, | |||
134: 0.85, | |||
139: 1, | |||
148: 1, | |||
150: 0.85, | |||
156: 1, | |||
157: 1, | |||
158: 1, | |||
159: 1, | |||
160: 0.9, | |||
161: 1, | |||
162: 1, | |||
163: 1, | |||
164: 0.8, | |||
165: 1, | |||
166: 0.95, | |||
167: 1, | |||
168: 1, | |||
169: 1 | |||
} | |||
}, | |||
uiLoginList: [ | |||
'login' | |||
], | |||
@@ -86,7 +163,11 @@ const config = { | |||
}; | |||
module.exports = { | |||
init: function () { | |||
config, | |||
atlasTextureDimensions: {}, | |||
init: async function () { | |||
events.emit('onBeforeGetClientConfig', config); | |||
//Deprecated | |||
@@ -95,15 +176,24 @@ module.exports = { | |||
events.emit('onBeforeGetContextMenuActions', config.contextMenuActions); | |||
events.emit('onBeforeGetTermsOfService', config.tos); | |||
events.emit('onBeforeGetTextureList', config.textureList); | |||
await this.calculateAtlasTextureDimensions(); | |||
}, | |||
//The client needs to know this as well as the map loader | |||
calculateAtlasTextureDimensions: async function () { | |||
for (const tex of config.atlasTextures) { | |||
const path = tex.includes('.png') ? `../${tex}` : `../client/images/${tex}.png`; | |||
const dimensions = await imageSize(path); | |||
delete dimensions.type; | |||
this.atlasTextureDimensions[tex] = dimensions; | |||
} | |||
}, | |||
//Used to send to clients | |||
getClientConfig: function (msg) { | |||
msg.callback(config); | |||
}, | |||
//Just used by the server | |||
get: function () { | |||
return config; | |||
} | |||
}; |
@@ -46,10 +46,10 @@ let startup = { | |||
components.init(this.onComponentsReady.bind(this)); | |||
}, | |||
onComponentsReady: function () { | |||
onComponentsReady: async function () { | |||
skins.init(); | |||
factions.init(); | |||
clientConfig.init(); | |||
await clientConfig.init(); | |||
server.init(this.onServerReady.bind(this)); | |||
}, | |||
@@ -8,17 +8,18 @@ | |||
"compression": "^1.7.4", | |||
"express": "^4.17.1", | |||
"express-minify": "^1.0.0", | |||
"google-spreadsheet": "^3.0.10", | |||
"google-spreadsheet": "^3.0.11", | |||
"image-size": "^0.8.3", | |||
"less-middleware": "^3.1.0", | |||
"npm-check-updates": "^7.0.1", | |||
"rethinkdbdash": "^2.3.31", | |||
"socket.io": "^2.3.0", | |||
"universal-analytics": "^0.4.20" | |||
"universal-analytics": "^0.4.22" | |||
}, | |||
"devDependencies": { | |||
"babel-eslint": "^10.1.0", | |||
"eslint": "^6.8.0", | |||
"eslint-plugin-prettier": "^3.1.2", | |||
"sqlite3": "^4.1.1" | |||
"eslint": "^7.4.0", | |||
"eslint-plugin-prettier": "^3.1.4", | |||
"sqlite3": "^5.0.0" | |||
} | |||
} |
@@ -20,7 +20,7 @@ module.exports = { | |||
lastTime: 0, | |||
init: async function (args) { | |||
init: function (args) { | |||
this.zoneId = args.zoneId; | |||
spellCallbacks.init(); | |||
@@ -47,7 +47,7 @@ module.exports = { | |||
spawners.init(fakeInstance); | |||
scheduler.init(); | |||
await map.create(); | |||
map.create(); | |||
if (map.mapFile.properties.isRandom) { | |||
if (!map.oldCollisionMap) | |||
map.oldCollisionMap = map.collisionMap; | |||
@@ -1,5 +1,3 @@ | |||
const imageSize = require('image-size'); | |||
let objects = require('../objects/objects'); | |||
let physics = require('./physics'); | |||
let spawners = require('./spawners'); | |||
@@ -120,8 +118,8 @@ module.exports = { | |||
this.spawn = [this.spawn]; | |||
} | |||
}, | |||
create: async function () { | |||
await this.getMapFile(); | |||
create: function () { | |||
this.getMapFile(); | |||
this.clientMap = { | |||
zoneId: -1, | |||
@@ -132,8 +130,9 @@ module.exports = { | |||
hiddenRooms: this.hiddenRooms | |||
}; | |||
}, | |||
getMapFile: async function () { | |||
await this.build(); | |||
getMapFile: function () { | |||
this.build(); | |||
this.randomMap = extend({}, randomMap); | |||
this.oldMap = this.layers; | |||
@@ -211,7 +210,7 @@ module.exports = { | |||
mapFile = null; | |||
}, | |||
build: async function () { | |||
build: function () { | |||
const mapSize = { | |||
w: mapFile.width, | |||
h: mapFile.height | |||
@@ -293,31 +292,20 @@ module.exports = { | |||
info.cell = data[index]; | |||
events.emit('onBeforeBuildLayerTile', info); | |||
await builders.tile(info); | |||
builders.tile(info); | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
getImageDimensions: async function (path) { | |||
let cachedDimensions = cachedImageDimensions[path]; | |||
if (!cachedDimensions) { | |||
cachedDimensions = await imageSize(path); | |||
cachedImageDimensions[path] = cachedDimensions; | |||
} | |||
return cachedDimensions; | |||
}, | |||
getOffsetCellPos: async function (sheetName, cell) { | |||
const atlasTextures = clientConfig.get().atlasTextures; | |||
getOffsetCellPos: function (sheetName, cell) { | |||
const { atlasTextureDimensions, config: { atlasTextures } } = clientConfig; | |||
const indexInAtlas = atlasTextures.indexOf(sheetName); | |||
let offset = 0; | |||
for (let i = 0; i < indexInAtlas; i++) { | |||
const path = '../client/images/' + atlasTextures[i] + '.png'; | |||
const dimensions = await this.getImageDimensions(path); | |||
const dimensions = atlasTextureDimensions[atlasTextures[i]]; | |||
offset += (dimensions.width / 8) * (dimensions.height / 8); | |||
} | |||
@@ -353,7 +341,7 @@ module.exports = { | |||
}; | |||
}, | |||
tile: async function (info) { | |||
tile: function (info) { | |||
let { x, y, cell, layer: layerName } = info; | |||
if (cell === 0) { | |||
@@ -366,7 +354,7 @@ module.exports = { | |||
let cellInfo = this.builders.getCellInfo(cell); | |||
let sheetName = cellInfo.sheetName; | |||
const offsetCell = await this.getOffsetCellPos(sheetName, cellInfo.cell); | |||
const offsetCell = this.getOffsetCellPos(sheetName, cellInfo.cell); | |||
if ((layerName !== 'hiddenWalls') && (layerName !== 'hiddenTiles')) { | |||
let layer = this.layers; | |||
@@ -21,7 +21,7 @@ let mapList = require('../config/maps/mapList'); | |||
let sheets = require('../security/sheets'); | |||
let itemEffects = require('../items/itemEffects'); | |||
let onCpnsReady = function () { | |||
let onCpnsReady = async function () { | |||
factions.init(); | |||
skins.init(); | |||
mtx.init(); | |||
@@ -34,7 +34,7 @@ let onCpnsReady = function () { | |||
recipes.init(); | |||
sheets.init(); | |||
itemEffects.init(); | |||
clientConfig.init(); | |||
await clientConfig.init(); | |||
process.send({ | |||
method: 'onReady' | |||