初始化和读档优化:不重建全部blocks

This commit is contained in:
ckcz123 2020-05-23 10:14:00 +08:00
parent 7707e9f689
commit 11f32eb701
13 changed files with 59 additions and 87 deletions

View File

@ -135,7 +135,7 @@ editor_game_wrapper = function (editor, main, core) {
// 获取当前地图
editor_game.prototype.fetchMapFromCore = function () {
var mapArray = core.maps.saveMap(core.status.floorId);
var mapArray = core.getMapArray(core.status.floorId, true);
editor.map = mapArray.map(function (v) {
return v.map(function (v) {
var x = parseInt(v), y = editor.indexs[x];

View File

@ -8,14 +8,14 @@ editor_table_wrapper = function (editor) {
// HTML模板
editor_table.prototype.select = function (value, values) {
var content = editor.table.option(value) +
values.map(function (v) {
return editor.table.option(v)
if (values.indexOf(value) < 0) values = [value].concat(values);
var content = values.map(function (v) {
return editor.table.option(v, v == value)
}).join('')
return /* html */`<select>\n${content}</select>\n`
}
editor_table.prototype.option = function (value) {
return /* html */`<option value='${JSON.stringify(value)}'>${JSON.stringify(value)}</option>\n`
editor_table.prototype.option = function (value, selected) {
return /* html */`<option value='${JSON.stringify(value)}' ${selected ? 'selected' : ''}>${JSON.stringify(value)}</option>\n`
}
editor_table.prototype.text = function (value) {
return /* html */`<input type='text' spellcheck='false' value='${JSON.stringify(value)}'/>\n`

View File

@ -1100,6 +1100,7 @@ control.prototype.updateDamage = function (floorId, ctx) {
control.prototype._updateDamage_damage = function (floorId, ctx) {
core.setTextAlign(ctx, 'left');
core.extractBlocks(floorId);
core.status.maps[floorId].blocks.forEach(function (block) {
var x = block.x, y = block.y;
if (!block.disable && block.event.cls.indexOf('enemy') == 0 && block.event.displayDamage !== false) {

View File

@ -299,6 +299,7 @@ enemys.prototype._getDamage = function (enemy, hero, x, y, floorId) {
enemys.prototype.getCurrentEnemys = function (floorId) {
floorId = floorId || core.status.floorId;
var enemys = [], used = {};
core.extractBlocks(floorId);
var mapBlocks = core.status.maps[floorId].blocks;
for (var b = 0; b < mapBlocks.length; b++) {
if (!mapBlocks[b].disable && mapBlocks[b].event.cls.indexOf('enemy') == 0) {
@ -364,6 +365,7 @@ enemys.prototype.hasEnemyLeft = function (enemyId, floorId) {
else if (enemyId) enemyMap[enemyId] = true;
else enemyMap = null;
for (var i = 0; i < floorId.length; i++) {
core.extractBlocks(floorId[i]);
var mapBlocks = core.status.maps[floorId[i]].blocks;
for (var b = 0; b < mapBlocks.length; b++) {
if (!mapBlocks[b].disable && mapBlocks[b].event.cls.indexOf('enemy') === 0) {

View File

@ -687,6 +687,7 @@ events.prototype._changeFloor_getHeroLoc = function (floorId, stair, heroLoc) {
heroLoc.y = core.status.maps[floorId][stair][1];
}
else {
core.extractBlocks(floorId);
var blocks = core.status.maps[floorId].blocks;
for (var i in blocks) {
if (!blocks[i].disable && blocks[i].event.id === stair) {

View File

@ -36,16 +36,13 @@ icons.prototype.getAllIconIds = function () {
return this.allIconIds;
}
icons.prototype._getAnimateFrames = function (cls, useOriginValue) {
icons.prototype._getAnimateFrames = function (cls) {
if (cls == 'enemys' || cls == 'npcs') {
return 2;
}
if (cls == 'animates' || cls == 'enemy48') {
if (cls == 'animates' || cls == 'enemy48' || cls == 'npc48') {
return 4;
}
if (cls == 'npc48') {
return useOriginValue ? 4 : 1;
}
return 1;
}

View File

@ -53,16 +53,27 @@ maps.prototype.loadFloor = function (floorId, map) {
if (notCopy.indexOf(name) == -1 && map[name] != null)
content[name] = core.clone(map[name]);
}
if (map.deleted) {
content['blocks'] = [];
return content;
content.map = map.map;
if (main.mode == 'editor') {
this.extractBlocks(content);
}
map = this.decompressMap(map.map, floorId);
// 事件处理
content['blocks'] = this._mapIntoBlocks(map, floor, floorId);
return content;
}
/// 根据需求解析出blocks
maps.prototype.extractBlocks = function (map) {
map = map || core.status.floorId;
if (typeof map == 'string') map = (core.status.maps||{})[map];
if (!map) return;
if (map.blocks) return;
if (map.deleted) {
map.blocks = [];
return;
}
var floorId = map.floorId;
map.blocks = this._mapIntoBlocks(this.decompressMap(map.map, floorId), core.floors[floorId], floorId);
}
maps.prototype._mapIntoBlocks = function (map, floor, floorId) {
var blocks = [];
var mw = core.floors[floorId].width;
@ -160,7 +171,7 @@ maps.prototype._addInfo = function (block) {
block.event.trigger = 'getItem';
}
if (block.event.animate == null) {
block.event.animate = core.icons._getAnimateFrames(block.event.cls, false);
block.event.animate = core.icons._getAnimateFrames(block.event.cls);
}
block.event.height = 32;
if (block.event.cls == 'enemy48' || block.event.cls == 'npc48')
@ -289,17 +300,16 @@ maps.prototype.saveMap = function (floorId) {
return map;
}
// 砍层状态:直接返回
if (main.mode == 'play' && (flags.__removed__ || []).indexOf(floorId) >= 0) {
if ((flags.__removed__ || []).indexOf(floorId) >= 0) {
return { deleted: true, canFlyTo: false, cannotViewMap: true };
}
var map = maps[floorId], floor = core.floors[floorId];
var blocks = this._getMapArrayFromBlocks(map.blocks, floor.width, floor.height, true);
if (main.mode == 'editor') return blocks;
var thisFloor = this._compressFloorData(map, floor);
var mapArr = this.compressMap(blocks, floorId);
if (mapArr != null) thisFloor.map = mapArr;
var map = maps[floorId];
var thisFloor = this._compressFloorData(map, core.floors[floorId]);
if (map.blocks) {
var mapArr = this.compressMap(map.blocks, map.width, map.height, floorId);
if (mapArr != null) thisFloor.map = mapArr;
}
return thisFloor;
}
@ -351,18 +361,12 @@ maps.prototype.resizeMap = function (floorId) {
////// 将当前地图重新变成二维数组形式 //////
maps.prototype.getMapArray = function (floorId, showDisable) {
floorId = floorId || core.status.floorId;
return this._getMapArrayFromBlocks(core.status.maps[floorId].blocks,
core.floors[floorId].width, core.floors[floorId].height, showDisable);
var map = core.status.maps[floorId];
if (!map.blocks) return map.map;
return this._getMapArrayFromBlocks(map.blocks, map.width, map.height, showDisable);
}
maps.prototype._getMapArrayFromBlocks = function (blockArray, width, height, showDisable) {
if (typeof blockArray == 'string') {
var floorId = blockArray;
blockArray = core.status.maps[floorId].blocks;
width = core.floors[floorId].width;
height = core.floors[floorId].height;
}
var blocks = [];
var allzero = [];
for (var y = 0; y < width; y++) allzero.push(0);
@ -386,6 +390,7 @@ maps.prototype._getMapArrayFromBlocks = function (blockArray, width, height, sho
maps.prototype.getMapBlocksObj = function (floorId, showDisable) {
floorId = floorId || core.status.floorId;
var obj = {};
core.extractBlocks(floorId);
core.status.maps[floorId].blocks.forEach(function (block) {
if (!block.disable || showDisable)
obj[block.x + "," + block.y] = block;
@ -775,6 +780,7 @@ maps.prototype.drawMap = function (floorId, callback) {
core.clearMap('all');
this.generateGroundPattern(floorId);
core.status.floorId = floorId;
core.extractBlocks(floorId);
core.status.thisMap = core.status.maps[floorId];
this._drawMap_drawAll();
@ -841,6 +847,7 @@ maps.prototype._drawBg_drawBackground = function (floorId, ctx) {
////// 绘制事件层 //////
maps.prototype.drawEvents = function (floorId, blocks, ctx) {
floorId = floorId || core.status.floorId;
core.extractBlocks(floorId);
if (!blocks) blocks = core.status.maps[floorId].blocks;
var arr = this._getMapArrayFromBlocks(blocks, core.floors[floorId].width, core.floors[floorId].height);
var onMap = ctx == null;
@ -1193,6 +1200,7 @@ maps.prototype.drawThumbnail = function (floorId, blocks, options, toDraw) {
}
maps.prototype._drawThumbnail_drawTempCanvas = function (floorId, blocks, options) {
core.extractBlocks(floorId);
blocks = blocks || core.status.maps[floorId].blocks;
options = options || {}
@ -1329,6 +1337,7 @@ maps.prototype.enemyExists = function (x, y, id, floorId) {
maps.prototype.getBlock = function (x, y, floorId, showDisable) {
floorId = floorId || core.status.floorId;
if (!floorId) return null;
core.extractBlocks(floorId);
var blocks = core.status.maps[floorId].blocks;
for (var n = 0; n < blocks.length; n++) {
if (blocks[n].x == x && blocks[n].y == y) {
@ -1406,6 +1415,7 @@ maps.prototype.searchBlock = function (id, floorId, showDisable) {
});
return result;
}
core.extractBlocks(floorId);
for (var i = 0; i < core.status.maps[floorId].blocks.length; ++i) {
var block = core.status.maps[floorId].blocks[i];
if ((showDisable || !block.disable) && (core.matchWildcard(id, block.event.id) || core.matchRegex(id, block.event.id))) {
@ -1461,7 +1471,7 @@ maps.prototype.hideBlock = function (x, y, floorId) {
maps.prototype.hideBlockByIndex = function (index, floorId) {
floorId = floorId || core.status.floorId;
if (!floorId) return;
core.extractBlocks(floorId);
var blocks = core.status.maps[floorId].blocks, block = blocks[index];
block.disable = true;
}
@ -1501,7 +1511,7 @@ maps.prototype.removeBlock = function (x, y, floorId) {
maps.prototype.removeBlockByIndex = function (index, floorId) {
floorId = floorId || core.status.floorId;
if (!floorId) return;
core.extractBlocks(floorId);
var blocks = core.status.maps[floorId].blocks, block = blocks[index];
blocks.splice(index, 1);
}
@ -1754,6 +1764,7 @@ maps.prototype.replaceBlock = function (fromNumber, toNumber, floorId) {
return;
}
var toBlock = this.getBlockByNumber(toNumber, true);
core.extractBlocks(floorId);
core.status.maps[floorId].blocks.forEach(function (block) {
if (block.id == fromNumber) {
block.id = toNumber;
@ -1903,7 +1914,7 @@ maps.prototype.moveBlock = function (x, y, steps, time, keep, callback) {
}
maps.prototype._moveBlock_doMove = function (blockInfo, canvases, moveInfo, callback) {
var animateTotal = core.icons._getAnimateFrames(blockInfo.cls, true), animateTime = 0;
var animateTotal = core.icons._getAnimateFrames(blockInfo.cls), animateTime = 0;
var animate = window.setInterval(function () {
if (blockInfo.cls != 'tileset') {
animateTime += moveInfo.per_time;

View File

@ -2643,7 +2643,9 @@ ui.prototype._drawSLPanel_drawRecord = function(title, data, x, y, size, cho, hi
core.fillText('ui', title, x, y, highLight?'#FFD700':'#FFFFFF', this._buildFont(17, true));
core.strokeRect('ui', x-size/2, y+15, size, size, cho?strokeColor:'#FFFFFF', cho?6:2);
if (data && data.floorId) {
core.drawThumbnail(data.floorId, core.maps.loadMap(data.maps, data.floorId).blocks, {
var map = core.maps.loadMap(data.maps, data.floorId);
core.extractBlocks(map);
core.drawThumbnail(data.floorId, map.blocks, {
heroLoc: data.hero.loc, heroIcon: data.hero.image, flags: data.hero.flags
}, {
ctx: 'ui', x: x-size/2, y: y+15, size: size, centerX: data.hero.loc.x, centerY: data.hero.loc.y
@ -2813,6 +2815,7 @@ ui.prototype._drawStatistics_add = function (floorId, obj, x1, x2, value) {
}
ui.prototype._drawStatistics_floorId = function (floorId, obj) {
core.extractBlocks(floorId);
var floor = core.status.maps[floorId], blocks = floor.blocks;
// 隐藏层不给看
if (floor.cannotViewMap && floorId!=core.status.floorId) return;

View File

@ -1128,51 +1128,6 @@ utils.prototype.same = function (a, b) {
return false;
}
utils.prototype._export = function (floorIds) {
if (!floorIds) floorIds = [core.status.floorId];
else if (floorIds == 'all') floorIds = core.clone(core.floorIds);
else if (typeof floorIds == 'string') floorIds = [floorIds];
var monsterMap = {};
// map
var content = floorIds.length + "\n" + core.__SIZE__ + " " + core.__SIZE__ + "\n\n";
floorIds.forEach(function (floorId) {
var arr = core.maps._getMapArrayFromBlocks(core.status.maps[floorId].blocks, core.__SIZE__, core.__SIZE__);
content += arr.map(function (x) {
// check monster
x.forEach(function (t) {
var block = core.maps.getBlockByNumber(t);
if (block.event.cls.indexOf("enemy") == 0) {
monsterMap[t] = block.event.id;
}
})
return x.join("\t");
}).join("\n") + "\n\n";
})
// values
content += ["redGem", "blueGem", "greenGem", "redPotion", "bluePotion",
"yellowPotion", "greenPotion", "sword1", "shield1"].map(function (x) {
return core.values[x] || 0;
}).join(" ") + "\n\n";
// monster
content += Object.keys(monsterMap).length + "\n";
for (var t in monsterMap) {
var id = monsterMap[t], monster = core.material.enemys[id];
content += t + " " + monster.hp + " " + monster.atk + " " +
monster.def + " " + monster.money + " " + monster.special + "\n";
}
content += "\n0 0 0 0 0 0\n\n";
content += core.status.hero.hp + " " + core.status.hero.atk + " "
+ core.status.hero.def + " " + core.status.hero.mdef + " " + core.status.hero.money + " "
+ core.itemCount('yellowKey') + " " + core.itemCount("blueKey") + " " + core.itemCount("redKey") + " 0 "
+ core.status.hero.loc.x + " " + core.status.hero.loc.y + "\n";
console.log(content);
}
utils.prototype.unzip = function (blobOrUrl, success, error, convertToText, onprogress) {
var _error = function (msg) {
main.log(msg);

View File

@ -115,6 +115,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
core.status.hero.loc = heroLoc;
// 检查重生怪并重置
if (!fromLoad) {
core.extractBlocks(floorId);
core.status.maps[floorId].blocks.forEach(function (block) {
if (block.disable && core.enemys.hasSpecial(block.event.id, 23)) {
block.disable = false;
@ -520,6 +521,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
var cache = core.status.checkBlock.cache[index];
if (!cache) {
// 没有该点的缓存,则遍历每个图块
core.extractBlocks(floorId);
core.status.maps[floorId].blocks.forEach(function (block) {
if (!block.disable) {
// 获得该图块的ID

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

@ -28,7 +28,7 @@
(已完成!) 清除最近使用图块
(已完成!) cannotIn / cannotOut使用选项框
(已完成!) noPass->canPass改成选择框
初始化&读档优化:不一次读取全部楼层并创建
(已完成!) 初始化&读档优化:不一次读取全部楼层并创建
(已完成!) 绿钥匙进状态栏
(已完成!) 图块ID不可全数字
(已完成!) 怪物详细信息富文本化
@ -48,7 +48,7 @@
(已完成!) 道具效果优化,删除部分道具相关的开关
(已完成!) 素材列表选择
(已完成!) 油漆桶,动态更改地图大小
地图拉框选择复制剪切删除
(已完成!) 地图拉框选择复制剪切删除
(已完成!) 额外素材区拖动选择一个区域
(已完成!) 素材替换
(已完成!) 大屏幕下放大游戏界面
@ -66,7 +66,7 @@
(已完成!) 更多的图块blockly化
(已完成!) 勇士帧动画
(不处理;现在静止状态可以有帧动画了,所以不考虑行走过程动画) 行走动画
合并main中一些设置内容
(已完成!) 合并main中一些设置内容
(已完成!) \t[this], 勇士朝下flag:arg清理瞬移扣血
-------------