mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-04-09 23:28:50 +02:00
Reduce code complexity
This commit is contained in:
parent
59d1934a34
commit
b0d19f529f
@ -113,9 +113,8 @@ export default class BrailleBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO Optimize this part
|
//TODO Optimize this part
|
||||||
var i, k;
|
|
||||||
const results = [];
|
const results = [];
|
||||||
for (i = k = 1; k <= 255; i = ++k) {
|
for (let i = 1; i <= 255; i++) {
|
||||||
const braille = (i & 7) + ((i & 56) << 1) + ((i & 64) >> 3) + (i & 128);
|
const braille = (i & 7) + ((i & 56) << 1) + ((i & 64) >> 3) + (i & 128);
|
||||||
results.push(this.asciiToBraille[i] = masks.reduce((function(best, mask) {
|
results.push(this.asciiToBraille[i] = masks.reduce((function(best, mask) {
|
||||||
const covered = utils.population(mask.mask & braille);
|
const covered = utils.population(mask.mask & braille);
|
||||||
|
@ -163,9 +163,8 @@ export default class Canvas {
|
|||||||
const b = this._bresenham(pointA, pointC);
|
const b = this._bresenham(pointA, pointC);
|
||||||
const c = this._bresenham(pointA, pointB);
|
const c = this._bresenham(pointA, pointB);
|
||||||
|
|
||||||
const points = a.concat(b).concat(c).filter((point) => {
|
const points = a.concat(b).concat(c).filter(({y}) => {
|
||||||
var ref;
|
return 0 <= y && y < this.height;
|
||||||
return (0 <= (ref = point.y) && ref < this.height);
|
|
||||||
}).sort(function(a, b) {
|
}).sort(function(a, b) {
|
||||||
if (a.y === b.y) {
|
if (a.y === b.y) {
|
||||||
return a.x - b.x;
|
return a.x - b.x;
|
||||||
|
@ -13,7 +13,6 @@ export default class Styler {
|
|||||||
constructor(style) {
|
constructor(style) {
|
||||||
this.styleById = {};
|
this.styleById = {};
|
||||||
this.styleByLayer = {};
|
this.styleByLayer = {};
|
||||||
var base, name;
|
|
||||||
this.styleName = style.name;
|
this.styleName = style.name;
|
||||||
if (style.constants) {
|
if (style.constants) {
|
||||||
this._replaceConstants(style.constants, style.layers);
|
this._replaceConstants(style.constants, style.layers);
|
||||||
@ -30,10 +29,7 @@ export default class Styler {
|
|||||||
|
|
||||||
layer.appliesTo = this._compileFilter(layer.filter);
|
layer.appliesTo = this._compileFilter(layer.filter);
|
||||||
|
|
||||||
//TODO Better translation of: @styleByLayer[style['source-layer']] ?= []
|
this.styleByLayer[layer['source-layer']] ??= [];
|
||||||
if ((base = this.styleByLayer)[name = layer['source-layer']] == null) {
|
|
||||||
base[name] = [];
|
|
||||||
}
|
|
||||||
this.styleByLayer[layer['source-layer']].push(layer);
|
this.styleByLayer[layer['source-layer']].push(layer);
|
||||||
this.styleById[layer.id] = layer;
|
this.styleById[layer.id] = layer;
|
||||||
}
|
}
|
||||||
|
12
src/Tile.js
12
src/Tile.js
@ -18,14 +18,10 @@ export default class Tile {
|
|||||||
this.styler = styler;
|
this.styler = styler;
|
||||||
}
|
}
|
||||||
|
|
||||||
load(buffer) {
|
async load(buffer) {
|
||||||
return this._unzipIfNeeded(buffer).then((buffer) => {
|
const unzippedBuffer = await this._unzipIfNeeded(buffer);
|
||||||
return this._loadTile(buffer);
|
await this._loadTile(unzippedBuffer);
|
||||||
}).then(() => {
|
await this._loadLayers();
|
||||||
return this._loadLayers();
|
|
||||||
}).then(() => {
|
|
||||||
return this;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_loadTile(buffer) {
|
_loadTile(buffer) {
|
||||||
|
@ -133,12 +133,13 @@ export default class TileSource {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_createTile(z, x, y, buffer) {
|
async _createTile(z, x, y, buffer) {
|
||||||
const name = [z, x, y].join('-');
|
const name = [z, x, y].join('-');
|
||||||
this.cached.push(name);
|
this.cached.push(name);
|
||||||
|
|
||||||
const tile = this.cache[name] = new Tile(this.styler);
|
const tile = this.cache[name] = new Tile(this.styler);
|
||||||
return tile.load(buffer);
|
await tile.load(buffer);
|
||||||
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
_initPersistence() {
|
_initPersistence() {
|
||||||
|
Loading…
Reference in New Issue
Block a user