editor-tilesets

This commit is contained in:
YouWei Zhao 2018-09-26 23:39:36 +08:00
parent f1c4ab8dd4
commit 458e464f73
6 changed files with 62 additions and 12 deletions

View File

@ -16,7 +16,12 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"images": { "images": {
"_leaf": true, "_leaf": true,
"_type": "textarea", "_type": "textarea",
"_data": "在此存放所有可能使用的图片 \n 图片可以被作为背景图(的一部分),也可以直接用自定义事件进行显示。 \n 图片名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好 \n 建议对于较大的图片,在网上使用在线的“图片压缩工具(http://compresspng.com/zh/)”来进行压缩,以节省流量 \n 依次向后添加" "_data": "在此存放所有可能使用的图片tilesets除外 \n 图片可以被作为背景图(的一部分),也可以直接用自定义事件进行显示。 \n 图片名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好 \n 建议对于较大的图片,在网上使用在线的“图片压缩工具(http://compresspng.com/zh/)”来进行压缩,以节省流量 \n 依次向后添加"
},
"tilesets": {
"_leaf": true,
"_type": "textarea",
"_data": "在此存放额外素材的图片名, \n 可以自定导入任意张素材图片无需PS无需注册即可直接在游戏中使用 \n 形式如[\"1.png\", \"2.png\"] ,将需要的素材图片放在images目录下 \n 素材的宽高必须都是32的倍数且图片上的总图块数不超过1000即最多有1000个32*32的图块在该图片上"
}, },
"animates": { "animates": {
"_leaf": true, "_leaf": true,

View File

@ -81,7 +81,8 @@ editor.prototype.init = function (callback) {
editor.prototype.idsInit = function (maps, icons) { editor.prototype.idsInit = function (maps, icons) {
editor.ids = [0]; editor.ids = [0];
editor.indexs = []; editor.indexs = [];
var MAX_NUM = 1000; var MAX_NUM = Math.max.apply(null,Object.keys(maps_90f36752_8815_4be8_b32b_d7fad1d0542e));
editor.MAX_NUM=MAX_NUM;
var getInfoById = function (id) { var getInfoById = function (id) {
var block = maps.initBlock(0, 0, id); var block = maps.initBlock(0, 0, id);
if (hasOwnProp(block, 'event')) { if (hasOwnProp(block, 'event')) {
@ -89,7 +90,7 @@ editor.prototype.idsInit = function (maps, icons) {
} }
} }
var point = 0; var point = 0;
for (var i = 0; i < MAX_NUM; i++) { for (var i = 0; i <= MAX_NUM; i++) {
var indexBlock = getInfoById(i); var indexBlock = getInfoById(i);
editor.indexs[i] = []; editor.indexs[i] = [];
if (indexBlock) { if (indexBlock) {
@ -106,6 +107,21 @@ editor.prototype.idsInit = function (maps, icons) {
} }
} }
editor.indexs[0] = [0]; editor.indexs[0] = [0];
var startOffset = core.icons.tilesetStartOffset;
for (var i in core.tilesets) {
var imgName = core.tilesets[i];
var img = core.material.images.tilesets[imgName];
var width = Math.floor(img.width/32), height = Math.floor(img.height/32);
for (var id=startOffset; id<startOffset+width*height;id++) {
var x = (id-startOffset)%width, y = parseInt((id-startOffset)/width);
var indexBlock = getInfoById(id);
editor.ids.push({'idnum': id, 'id': indexBlock.event.id, 'images': imgName, "x": x, "y": y, isTile: true});
point++;
editor.indexs[id]=[point];
}
startOffset += core.icons.tilesetStartOffset;
}
} }
editor.prototype.mapInit = function () { editor.prototype.mapInit = function () {
@ -319,6 +335,14 @@ editor.prototype.drawInitData = function (icons) {
sumWidth += images[img].width; sumWidth += images[img].width;
maxHeight = Math.max(maxHeight, images[img].height); maxHeight = Math.max(maxHeight, images[img].height);
} }
var tilesets = images.tilesets;
for (var ii in core.tilesets) {
var img = core.tilesets[ii];
editor.widthsX[img] = [img, sumWidth / 32, (sumWidth + tilesets[img].width) / 32, tilesets[img].height];
sumWidth += tilesets[img].width;
maxHeight = Math.max(maxHeight, tilesets[img].height);
}
var fullWidth = ~~(sumWidth * ratio); var fullWidth = ~~(sumWidth * ratio);
var fullHeight = ~~(maxHeight * ratio); var fullHeight = ~~(maxHeight * ratio);
@ -340,11 +364,17 @@ editor.prototype.drawInitData = function (icons) {
dc.drawImage(autotiles[im], nowx, nowy); dc.drawImage(autotiles[im], nowx, nowy);
nowy += autotiles[im].height; nowy += autotiles[im].height;
} }
nowx += 3 * 32;
continue; continue;
} }
dc.drawImage(images[img], nowx, 0) dc.drawImage(images[img], nowx, 0)
nowx += images[img].width; nowx += images[img].width;
} }
for (var ii in core.tilesets) {
var img = core.tilesets[ii];
dc.drawImage(tilesets[img], nowx, 0)
nowx += tilesets[img].width;
}
//editor.drawMapBg(); //editor.drawMapBg();
//editor.mapInit(); //editor.mapInit();
} }
@ -742,9 +772,9 @@ editor.prototype.listen = function () {
if (pos.x >= editor.widthsX[spriter][1] && pos.x < editor.widthsX[spriter][2]) { if (pos.x >= editor.widthsX[spriter][1] && pos.x < editor.widthsX[spriter][2]) {
var ysize = spriter.indexOf('48') === -1 ? 32 : 48; var ysize = spriter.indexOf('48') === -1 ? 32 : 48;
loc.ysize = ysize; loc.ysize = ysize;
pos.y = ~~(loc.y / loc.ysize);
pos.x = editor.widthsX[spriter][1];
pos.images = editor.widthsX[spriter][0]; pos.images = editor.widthsX[spriter][0];
pos.y = ~~(loc.y / loc.ysize);
if(core.tilesets.indexOf(pos.images)==-1)pos.x = editor.widthsX[spriter][1];
var autotiles = core.material.images['autotile']; var autotiles = core.material.images['autotile'];
if (pos.images == 'autotile') { if (pos.images == 'autotile') {
var imNames = Object.keys(autotiles); var imNames = Object.keys(autotiles);
@ -773,13 +803,17 @@ editor.prototype.listen = function () {
} else { } else {
if (hasOwnProp(autotiles, pos.images)) editor.info = {'images': pos.images, 'y': 0}; if (hasOwnProp(autotiles, pos.images)) editor.info = {'images': pos.images, 'y': 0};
else if (pos.images == 'terrains') editor.info = {'images': pos.images, 'y': pos.y - 1}; else if (pos.images == 'terrains') editor.info = {'images': pos.images, 'y': pos.y - 1};
else if (core.tilesets.indexOf(pos.images)!=-1) editor.info = {'images': pos.images, 'y': pos.y, 'x': pos.x-editor.widthsX[spriter][1]};
else editor.info = {'images': pos.images, 'y': pos.y}; else editor.info = {'images': pos.images, 'y': pos.y};
for (var ii = 0; ii < editor.ids.length; ii++) { for (var ii = 0; ii < editor.ids.length; ii++) {
if (( editor.info.images == editor.ids[ii].images if ((core.tilesets.indexOf(pos.images)!=-1 && editor.info.images == editor.ids[ii].images
&& editor.info.y == editor.ids[ii].y ) && editor.info.y == editor.ids[ii].y && editor.info.x == editor.ids[ii].x)
|| (hasOwnProp(autotiles, pos.images) && editor.info.images == editor.ids[ii].id || (hasOwnProp(autotiles, pos.images) && editor.info.images == editor.ids[ii].id
&& editor.info.y == editor.ids[ii].y)) { && editor.info.y == editor.ids[ii].y)
|| (core.tilesets.indexOf(pos.images)==-1 && editor.info.images == editor.ids[ii].images
&& editor.info.y == editor.ids[ii].y )
) {
editor.info = editor.ids[ii]; editor.info = editor.ids[ii];
break; break;

View File

@ -320,10 +320,18 @@ editor_mode = function (editor) {
if (!core.isset(editor_mode.info.id)) { if (!core.isset(editor_mode.info.id)) {
// document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML = ''; // document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML = '';
document.getElementById('enemyItemTable').style.display = 'none'; document.getElementById('enemyItemTable').style.display = 'none';
document.getElementById('tilesetsDiv').style.display = 'none';
document.getElementById('newIdIdnum').style.display = 'block'; document.getElementById('newIdIdnum').style.display = 'block';
return; return;
} }
if (editor_mode.info.isTile) {
document.getElementById('enemyItemTable').style.display = 'none';
document.getElementById('tilesetsDiv').style.display = 'block';
document.getElementById('newIdIdnum').style.display = 'none';
return;
}
document.getElementById('newIdIdnum').style.display = 'none'; document.getElementById('newIdIdnum').style.display = 'none';
document.getElementById('tilesetsDiv').style.display = 'none';
document.getElementById('enemyItemTable').style.display = 'block'; document.getElementById('enemyItemTable').style.display = 'block';
var objs = []; var objs = [];

View File

@ -95,10 +95,7 @@ var editArea = new Vue({
var num = mapArray[y][x]; var num = mapArray[y][x];
if (num == 0) if (num == 0)
editor.map[y][x] = 0; editor.map[y][x] = 0;
else if (num >= 1000) { else if (typeof(editor.indexs[num][0]) == 'undefined') {
that.error = 3;
editor.map[y][x] = undefined;
} else if (typeof(editor.indexs[num][0]) == 'undefined') {
that.error = 2; that.error = 2;
editor.map[y][x] = undefined; editor.map[y][x] = undefined;
} else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]]; } else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]];

View File

@ -92,6 +92,9 @@
<h3 class="leftTabHeader">图块属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button> <h3 class="leftTabHeader">图块属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>
</h3> </h3>
<div class="leftTabContent"> <div class="leftTabContent">
<div id='tilesetsDiv'><!-- tilesets -->
<p>tilesets不允许编辑图块属性</p>
</div>
<div id='newIdIdnum'><!-- id and idnum --> <div id='newIdIdnum'><!-- id and idnum -->
<input placeholder="新id唯一标识符"/> <input placeholder="新id唯一标识符"/>
<input placeholder="新idnum1000以内数字"/> <input placeholder="新idnum1000以内数字"/>

View File

@ -91,6 +91,9 @@
<h3 class="leftTabHeader">图块属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button> <h3 class="leftTabHeader">图块属性&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>
</h3> </h3>
<div class="leftTabContent"> <div class="leftTabContent">
<div id='tilesetsDiv'><!-- tilesets -->
<p>tilesets不允许编辑图块属性</p>
</div>
<div id='newIdIdnum'><!-- id and idnum --> <div id='newIdIdnum'><!-- id and idnum -->
<input placeholder="新id唯一标识符"/> <input placeholder="新id唯一标识符"/>
<input placeholder="新idnum1000以内数字"/> <input placeholder="新idnum1000以内数字"/>