大地图绘制缩略图

This commit is contained in:
ckcz123 committed 2020-07-03 22:12:15 +08:00
1 parent bde409bae2
commit 3523358cba
15 files changed
+205 -133

No files matched your search

+6 -2
View File
@@ -2725,6 +2725,10 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"!doc": "深拷贝一个对象(函数将原样返回)<br/>例如:core.clone(core.status.hero, (name, value) => (name == 'items' || typeof value == 'number'), false); // 深拷贝主角的属性和道具<br/>data: 待拷贝对象<br/>filter: 过滤器,可选,表示data为数组或对象时拷贝哪些项或属性,true表示拷贝<br/>recursion: 过滤器是否递归,可选。true表示过滤器也被递归<br/>返回值:拷贝的结果,注意函数将原样返回",
"!type": "fn(data?: ?, filter?: fn(name: string, value: ?) -> bool, recursion?: bool)"
},
"cloneArray": {
"!doc": "深拷贝一个1D或2D数组对象<br/>例如:core.cloneArray(core.status.thisMap.map)",
"!type": "fn(data?: [number]|[[number]]) -> [number]|[[number]]"
},
"setLocalForage": {
"!doc": "往数据库写入一段数据",
"!type": "fn(key: string, value?: ?, successCallback?: fn(), errorCallback?: fn())"
@@ -3275,8 +3279,8 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"!type": "fn(x?: number, y?: number, direction?: string, floorId?: string) -> bool"
},
"drawThumbnail": {
"!doc": "绘制缩略图<br/>例如:core.drawThumbnail(); // 绘制当前地图的缩略图<br/>floorId: 地图id,不填视为当前地图<br/>blocks: 一般不需要<br/>options: 额外的绘制项,可选。可以增绘主角位置和朝向、采用不同于游戏中的主角行走图、增绘显伤、提供flags用于存读档<br/>toDraw: 要绘制到的画布名或画布的ctx或还有其他信息,如起绘坐标、绘制大小、是否绘制全图、截取中心",
"!type": "fn(floorId?: string, blocks?: [block], options?: ?, toDraw?: string|CanvasRenderingContext2D|?)"
"!doc": "绘制缩略图<br/>例如:core.drawThumbnail(); // 绘制当前地图的缩略图<br/>floorId: 地图id,不填视为当前地图<br/>blocks: 一般不需要<br/>options: 绘制信息,可选。可以增绘主角位置和朝向、采用不同于游戏中的主角行走图、增绘显伤、提供flags用于存读档,同时包含要绘制到的画布名或画布的ctx或还有其他信息,如起绘坐标、绘制大小、是否绘制全图、截取中心",
"!type": "fn(floorId?: string, blocks?: [block], options?: ?)"
},
"hideBlockByIndex": {
"!doc": "根据图块的索引来隐藏图块",
+1 -1
View File
@@ -1 +1 @@
{"lastUsed":[{"idnum":151,"id":"autotile1","images":"autotile","y":0,"recent":1593758059851,"frequent":7},{"idnum":213,"id":"zombie","images":"enemys","y":12,"recent":1593758008027,"frequent":2},{"idnum":211,"id":"skeletonCaptain","images":"enemys","y":10,"recent":1593758003830,"frequent":2},{"idnum":206,"id":"bigBat","images":"enemys","y":5,"recent":1593758000245,"frequent":1},{"idnum":209,"id":"skeleton","images":"enemys","y":8,"recent":1593757393597,"frequent":4},{"idnum":210,"id":"skeletonWarrior","images":"enemys","y":9,"recent":1593757252851,"frequent":2},{"idnum":205,"id":"bat","images":"enemys","y":4,"recent":1593757205645,"frequent":1},{"idnum":201,"id":"greenSlime","images":"enemys","y":0,"recent":1593757197512,"frequent":1}],"foldPerCol":50,"folded":false,"editorLastFloorId":"sample2","disableBlocklyReplace":false,"disableBlocklyExpandCompare":false,"shortcut":{"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0}}
{"lastUsed":[{"idnum":45,"id":"book","images":"items","y":9,"recent":1593783767918,"frequent":1},{"idnum":151,"id":"autotile1","images":"autotile","y":0,"recent":1593758059851,"frequent":7},{"idnum":213,"id":"zombie","images":"enemys","y":12,"recent":1593758008027,"frequent":2},{"idnum":211,"id":"skeletonCaptain","images":"enemys","y":10,"recent":1593758003830,"frequent":2},{"idnum":206,"id":"bigBat","images":"enemys","y":5,"recent":1593758000245,"frequent":1},{"idnum":209,"id":"skeleton","images":"enemys","y":8,"recent":1593757393597,"frequent":4},{"idnum":210,"id":"skeletonWarrior","images":"enemys","y":9,"recent":1593757252851,"frequent":2},{"idnum":205,"id":"bat","images":"enemys","y":4,"recent":1593757205645,"frequent":1},{"idnum":201,"id":"greenSlime","images":"enemys","y":0,"recent":1593757197512,"frequent":1}],"foldPerCol":50,"folded":false,"editorLastFloorId":"sample2","disableBlocklyReplace":false,"disableBlocklyExpandCompare":false,"shortcut":{"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0},"viewportLoc":[0,0]}
+35 -22
View File
@@ -223,12 +223,17 @@ editor.prototype.init = function (callback) {
for (var one in canvases) {
canvases[one].width = canvases[one].height = core.__PIXELS__;
}
core.resetGame(core.firstData.hero, null, core.firstData.floorId, core.clone(core.initStatus.maps));
var lastFloorId = editor.config.get('editorLastFloorId', core.status.floorId);
if (core.floorIds.indexOf(lastFloorId) < 0) lastFloorId = core.status.floorId;
core.changeFloor(lastFloorId, null, {x: 0, y: 0, direction:"up"}, null, function () {
afterCoreReset();
}, true);
core.resetGame(core.firstData.hero, null, core.firstData.floorId, core.cloneArray(core.initStatus.maps));
var floorId = editor.config.get('editorLastFloorId', core.status.floorId);
if (core.floorIds.indexOf(floorId) < 0) floorId = core.status.floorId;
core.status.floorId = floorId;
core.resizeMap(floorId);
core.clearMap('all');
core.generateGroundPattern(floorId);
core.extractBlocks(floorId);
core.status.thisMap = core.status.maps[floorId];
afterCoreReset();
});
}
@@ -238,11 +243,13 @@ editor.prototype.init = function (callback) {
editor.drawInitData(core.icons.icons); // 初始化绘图
editor.game.fetchMapFromCore();
editor.pos = {x: 0, y: 0};
editor.updateMap();
editor.buildMark();
var viewportLoc = editor.config.get('viewportLoc', []);
editor.setViewport(viewportLoc[0] || 0, viewportLoc[1] || 0);
editor.drawEventBlock();
editor.pos = {x: 0, y: 0};
editor.mode.loc();
editor.info = editor.ids[editor.indexs[201]];
editor.mode.enemyitem();
@@ -334,20 +341,26 @@ editor.prototype.changeFloor = function (floorId, callback) {
editor.uivalues.preMapData = [];
editor.uivalues.postMapData = [];
editor.uifunctions._extraEvent_bindSpecialDoor_doAction(true);
core.changeFloor(floorId, null, {"x": 0, "y": 0, "direction": "up"}, null, function () {
editor.game.fetchMapFromCore();
editor.updateMap();
editor_mode.floor();
editor.drawEventBlock();
editor.viewportLoc = editor.viewportLoc || {};
var loc = editor.viewportLoc[floorId] || [], x = loc[0] || 0, y = loc[1] || 0;
editor.setViewport(x, y);
editor.uifunctions.unhighlightSaveFloorButton();
core.status.floorId = floorId;
core.resizeMap(floorId);
core.clearMap('all');
core.generateGroundPattern(floorId);
core.extractBlocks(floorId);
core.status.thisMap = core.status.maps[floorId];
editor.config.set('editorLastFloorId', floorId, function() {
if (callback) callback();
});
editor.game.fetchMapFromCore();
editor.updateMap();
editor_mode.floor();
editor.drawEventBlock();
editor.viewportLoc = editor.viewportLoc || {};
var loc = editor.viewportLoc[floorId] || [], x = loc[0] || 0, y = loc[1] || 0;
editor.setViewport(x, y);
editor.uifunctions.unhighlightSaveFloorButton();
editor.config.set('editorLastFloorId', floorId, function() {
if (callback) callback();
});
}
@@ -444,8 +457,7 @@ editor.prototype._updateMap_bigmap = function () {
bm.clearRect(0, 0, core.__PIXELS__, core.__PIXELS__);
bm.fillStyle = '#000000';
bm.fillRect(0, 0, core.__PIXELS__, core.__PIXELS__);
core.drawThumbnail(editor.currentFloorId, core.status.thisMap.blocks, null,
{ctx: bm, all: true});
core.drawThumbnail(editor.currentFloorId, core.status.thisMap.blocks, {ctx: bm, all: true});
var width = editor.currentFloorData.width;
var height = editor.currentFloorData.height;
editor.uivalues.bigmapInfo.top = core.__PIXELS__ * Math.max(0, (1 - height / width) / 2);
@@ -572,6 +584,7 @@ editor.prototype.setViewport=function (x, y) {
editor.viewportLoc = editor.viewportLoc || {};
editor.viewportLoc[editor.currentFloorId] = [core.bigmap.offsetX, core.bigmap.offsetY];
core.control.updateViewport();
editor.config.set('viewportLoc', editor.viewportLoc[editor.currentFloorId]);
editor.buildMark();
editor.drawPosSelection();
}
+6 -7
View File
@@ -375,7 +375,7 @@ editor_ui_wrapper = function (editor) {
// 绘制UI
var background = uievent.elements.selectBackground.value;
if (background == 'thumbnail') {
core.drawThumbnail(editor.currentFloorId, null, {}, 'uievent');
core.drawThumbnail(editor.currentFloorId, null, {ctx: 'uievent'});
}
else {
core.fillRect('uievent', 0, 0, core.__PIXELS__, core.__PIXELS__, background);
@@ -482,11 +482,10 @@ editor_ui_wrapper = function (editor) {
if (redraw) {
core.setAlpha('uievent', 1);
core.clearMap('uievent');
core.drawThumbnail(uievent.values.floorId, null, null,
{
ctx: 'uievent', centerX: uievent.values.left + core.__HALF_SIZE__,
centerY: uievent.values.top + core.__HALF_SIZE__, all: uievent.values.bigmap
});
core.drawThumbnail(uievent.values.floorId, null, {
ctx: 'uievent', centerX: uievent.values.left + core.__HALF_SIZE__,
centerY: uievent.values.top + core.__HALF_SIZE__, all: uievent.values.bigmap
});
uievent.values.multipoints = uievent.values.multipoints || [];
core.setTextAlign('uievent', 'right');
for (var i = 0; i < uievent.values.multipoints.length; ++i) {
@@ -857,7 +856,7 @@ editor_ui_wrapper = function (editor) {
var canvas = document.createElement('canvas');
canvas.width = canvas.height = core.__PIXELS__;
canvas.style.position = 'absolute';
core.drawThumbnail(editor.currentFloorId, null, {}, canvas.getContext('2d'));
core.drawThumbnail(editor.currentFloorId, null, {ctx: canvas.getContext('2d')});
dom.appendChild(canvas);
var canvas2 = document.createElement('canvas');
canvas2.style.position = 'absolute';