启动服务 & 优化splitImage
This commit is contained in:
parent
c70a466091
commit
ff1da6ebd9
@ -755,6 +755,27 @@ editor.prototype.drawInitData = function (icons) {
|
|||||||
});
|
});
|
||||||
var imgNames = ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48", "autotile"];
|
var imgNames = ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48", "autotile"];
|
||||||
|
|
||||||
|
var splitCanvas = document.createElement('canvas');
|
||||||
|
var splitCtx = splitCanvas.getContext('2d');
|
||||||
|
splitCtx.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
|
var splitImage = function (image, width, height) {
|
||||||
|
if (image.width == width && image.height == height) {
|
||||||
|
return [image];
|
||||||
|
}
|
||||||
|
var ans = [];
|
||||||
|
for (var j = 0; j < image.height; j += h) {
|
||||||
|
var h = Math.min(height, image.height - j);
|
||||||
|
splitCanvas.width = width;
|
||||||
|
splitCanvas.height = h;
|
||||||
|
core.drawImage(splitCtx, image, 0, j, width, h, 0, 0, width, h);
|
||||||
|
var data = new Image();
|
||||||
|
data.src = splitCanvas.toDataURL("image/png");
|
||||||
|
ans.push(data);
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
for (var ii = 0; ii < imgNames.length; ii++) {
|
for (var ii = 0; ii < imgNames.length; ii++) {
|
||||||
var img = imgNames[ii], tempy = 0;
|
var img = imgNames[ii], tempy = 0;
|
||||||
if (img == 'autotile') {
|
if (img == 'autotile') {
|
||||||
@ -862,9 +883,8 @@ editor.prototype.drawInitData = function (icons) {
|
|||||||
canvas.width = 32;
|
canvas.width = 32;
|
||||||
canvas.height = images[img].height + 64;
|
canvas.height = images[img].height + 64;
|
||||||
canvas.getContext('2d').drawImage(images[img], 0, 64);
|
canvas.getContext('2d').drawImage(images[img], 0, 64);
|
||||||
var subimgs = core.splitImage(canvas, 32, editor.uivalues.foldPerCol * 32);
|
var subimgs = splitImage(canvas, 32, editor.uivalues.foldPerCol * 32);
|
||||||
var frames = images[img].width / 32;
|
for (var i = 0; i < subimgs.length; i++) {
|
||||||
for (var i = 0; i < subimgs.length; i+=frames) {
|
|
||||||
drawImage(subimgs[i], nowx, 0, img);
|
drawImage(subimgs[i], nowx, 0, img);
|
||||||
nowx += 32;
|
nowx += 32;
|
||||||
}
|
}
|
||||||
@ -880,7 +900,7 @@ editor.prototype.drawInitData = function (icons) {
|
|||||||
var tempx = editor.uivalues.folded ? 32 : 96;
|
var tempx = editor.uivalues.folded ? 32 : 96;
|
||||||
for (var im in autotiles) {
|
for (var im in autotiles) {
|
||||||
var tempy = editor.uivalues.folded ? 32 : autotiles[im].height;
|
var tempy = editor.uivalues.folded ? 32 : autotiles[im].height;
|
||||||
var subimgs = core.splitImage(autotiles[im], tempx, tempy);
|
var subimgs = splitImage(autotiles[im], tempx, tempy);
|
||||||
drawImage(subimgs[0], nowx, nowy, img);
|
drawImage(subimgs[0], nowx, nowy, img);
|
||||||
nowy += tempy;
|
nowy += tempy;
|
||||||
}
|
}
|
||||||
@ -890,9 +910,8 @@ editor.prototype.drawInitData = function (icons) {
|
|||||||
if (editor.uivalues.folded) {
|
if (editor.uivalues.folded) {
|
||||||
// --- 单列 & 折行
|
// --- 单列 & 折行
|
||||||
var per_height = img.endsWith('48') ? 48 : 32;
|
var per_height = img.endsWith('48') ? 48 : 32;
|
||||||
var subimgs = core.splitImage(images[img], 32, editor.uivalues.foldPerCol * per_height);
|
var subimgs = splitImage(images[img], 32, editor.uivalues.foldPerCol * per_height);
|
||||||
var frames = images[img].width / 32;
|
for (var i = 0; i < subimgs.length; i++) {
|
||||||
for (var i = 0; i < subimgs.length; i+=frames) {
|
|
||||||
drawImage(subimgs[i], nowx, 0, img);
|
drawImage(subimgs[i], nowx, 0, img);
|
||||||
nowx += 32;
|
nowx += 32;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -348,7 +348,7 @@
|
|||||||
<div id='clearLoc' class="menuitem"><div class="menuitem-content">清空此点及事件</div></div>
|
<div id='clearLoc' class="menuitem"><div class="menuitem-content">清空此点及事件</div></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<select id="editModeSelect">
|
<select id="editModeSelect" style="font-size: 12px">
|
||||||
<option value="map">地图编辑</option>
|
<option value="map">地图编辑</option>
|
||||||
<option value="loc">地图选点</option>
|
<option value="loc">地图选点</option>
|
||||||
<option value="enemyitem">图块属性</option>
|
<option value="enemyitem">图块属性</option>
|
||||||
|
|||||||
@ -307,7 +307,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="tools">
|
<div class="tools">
|
||||||
<div id="tip"></div>
|
<div id="tip"></div>
|
||||||
<select id="editModeSelect" style="font-size: 13px">
|
<select id="editModeSelect" style="font-size: 12px">
|
||||||
<option value="map">地图编辑(Z)</option>
|
<option value="map">地图编辑(Z)</option>
|
||||||
<option value="loc">地图选点(X)</option>
|
<option value="loc">地图选点(X)</option>
|
||||||
<option value="enemyitem">图块属性(C)</option>
|
<option value="enemyitem">图块属性(C)</option>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user