core.__SIZE__

This commit is contained in:
oc 2019-03-16 23:30:38 +08:00
parent e208baab84
commit 87cd6a09de
3 changed files with 20 additions and 28 deletions

View File

@ -5,6 +5,9 @@
"use strict"; "use strict";
function core() { function core() {
this.__SIZE__ = 13;
this.__PIXELS__ = this.__SIZE__ * 32;
this.__HALF_SIZE__ = Math.floor(this.__SIZE__ / 2);
this.material = { this.material = {
'animates': {}, 'animates': {},
'images': {}, 'images': {},

View File

@ -2,10 +2,6 @@
function maps() { function maps() {
this._init(); this._init();
this.DEFAULT_WIDTH = 13;
this.DEFAULT_HEIGHT = 13;
this.DEFAULT_PIXEL_WIDTH = this.DEFAULT_WIDTH * 32;
this.DEFAULT_PIXEL_HEIGHT = this.DEFAULT_HEIGHT * 32;
} }
maps.prototype._init = function () { maps.prototype._init = function () {
@ -20,8 +16,8 @@ maps.prototype._setFloorSize = function (floorId) {
}); });
return; return;
} }
core.floors[floorId].width = core.floors[floorId].width || this.DEFAULT_WIDTH; core.floors[floorId].width = core.floors[floorId].width || core.__SIZE__;
core.floors[floorId].height = core.floors[floorId].height || this.DEFAULT_HEIGHT; core.floors[floorId].height = core.floors[floorId].height || core.__SIZE__;
} }
// ------ 加载地图与地图的存档读档(压缩与解压缩) ------ // // ------ 加载地图与地图的存档读档(压缩与解压缩) ------ //
@ -290,8 +286,8 @@ maps.prototype.resizeMap = function (floorId) {
core.canvas[cn].canvas.style.width = cwidth * core.domStyle.scale + "px"; core.canvas[cn].canvas.style.width = cwidth * core.domStyle.scale + "px";
core.canvas[cn].canvas.style.height = cheight * core.domStyle.scale + "px"; core.canvas[cn].canvas.style.height = cheight * core.domStyle.scale + "px";
if (main.mode === 'editor' && editor.isMobile) { if (main.mode === 'editor' && editor.isMobile) {
core.canvas[cn].canvas.style.width = core.bigmap.width * 32 / core.maps.DEFAULT_PIXEL_WIDTH * 96 + "vw"; core.canvas[cn].canvas.style.width = core.bigmap.width * 32 / core.__PIXELS__ * 96 + "vw";
core.canvas[cn].canvas.style.height = core.bigmap.height * 32 / core.maps.DEFAULT_PIXEL_HEIGHT * 96 + "vw"; core.canvas[cn].canvas.style.height = core.bigmap.height * 32 / core.__PIXELS__ * 96 + "vw";
} }
}); });
} }
@ -522,8 +518,8 @@ maps.prototype.drawBlock = function (block, animate) {
var x = block.x, y = block.y; var x = block.x, y = block.y;
// --- 在界面外的动画不绘制 // --- 在界面外的动画不绘制
if (redraw && block.event.animate > 1 && if (redraw && block.event.animate > 1 &&
(32 * x < core.bigmap.offsetX - 64 || 32 * x > core.bigmap.offsetX + this.DEFAULT_PIXEL_WIDTH + 32 (32 * x < core.bigmap.offsetX - 64 || 32 * x > core.bigmap.offsetX + core.__PIXELS__ + 32
|| 32 * y < core.bigmap.offsetY - 64 || 32 * y > core.bigmap.offsetY + this.DEFAULT_PIXEL_HEIGHT + 32 + 16)) { || 32 * y < core.bigmap.offsetY - 64 || 32 * y > core.bigmap.offsetY + core.__PIXELS__ + 32 + 16)) {
return; return;
} }
@ -586,7 +582,7 @@ maps.prototype.drawMap = function (floorId, callback) {
this._drawMap_drawAll(); this._drawMap_drawAll();
if (core.isset(core.status.curtainColor)) { if (core.isset(core.status.curtainColor)) {
core.fillRect('curtain', 0, 0, this.DEFAULT_PIXEL_WIDTH, this.DEFAULT_PIXEL_HEIGHT, core.fillRect('curtain', 0, 0, core.__PIXELS__, core.__PIXELS__,
core.arrayToRGBA(core.status.curtainColor)); core.arrayToRGBA(core.status.curtainColor));
} }
core.drawHero(); core.drawHero();
@ -611,7 +607,7 @@ maps.prototype._drawMap_drawBlockInfo = function (ctx, block, blockInfo, arr, on
} }
if (!onMap) { if (!onMap) {
var height = blockInfo.height; var height = blockInfo.height;
core.drawImage(ctx, blockInfo.image, 32 * blockInfo.posX, height * blockInfo.posY, 32, height, 32 * block.x, 32 * block.y, 32, height); core.drawImage(ctx, blockInfo.image, 32 * blockInfo.posX, height * blockInfo.posY, 32, height, 32 * block.x, 32 * block.y + 32 - height, 32, height);
return; return;
} }
this.drawBlock(block); this.drawBlock(block);
@ -653,10 +649,9 @@ maps.prototype.drawEvents = function (floorId, blocks, ctx) {
if (onMap) ctx = core.canvas.event; if (onMap) ctx = core.canvas.event;
blocks.filter(function (block) { blocks.filter(function (block) {
return block.event && !block.disable; return block.event && !block.disable;
}) }).forEach(function (block) {
.forEach(function (block) { core.maps._drawMap_drawBlockInfo(ctx, block, core.maps.getBlockInfo(block), arr, onMap);
core.maps._drawMap_drawBlockInfo(ctx, block, core.maps.getBlockInfo(block), arr, onMap); });
});
if (onMap) core.status.autotileAnimateObjs.map = core.clone(arr); if (onMap) core.status.autotileAnimateObjs.map = core.clone(arr);
} }
@ -962,7 +957,7 @@ maps.prototype._drawThumbnail_drawToTarget = function (floorId, toDraw) {
if (typeof toDraw == 'string' || toDraw.canvas) toDraw = {ctx: toDraw}; if (typeof toDraw == 'string' || toDraw.canvas) toDraw = {ctx: toDraw};
var ctx = core.getContextByName(toDraw.ctx); var ctx = core.getContextByName(toDraw.ctx);
if (ctx == null) return; if (ctx == null) return;
var x = toDraw.x || 0, y = toDraw.y || 0, size = toDraw.size || this.DEFAULT_PIXEL_WIDTH; var x = toDraw.x || 0, y = toDraw.y || 0, size = toDraw.size || core.__PIXELS__;
var width = core.floors[floorId].width, height = core.floors[floorId].height; var width = core.floors[floorId].width, height = core.floors[floorId].height;
var centerX = toDraw.centerX, centerY = toDraw.centerY; var centerX = toDraw.centerX, centerY = toDraw.centerY;
if (!core.isset(centerX)) centerX = Math.floor(width / 2); if (!core.isset(centerX)) centerX = Math.floor(width / 2);
@ -989,10 +984,9 @@ maps.prototype._drawThumbnail_drawToTarget = function (floorId, toDraw) {
} }
else { else {
// 只绘制可见窗口 // 只绘制可见窗口
var halfWidth = parseInt(this.DEFAULT_WIDTH / 2), halfHeight = parseInt(this.DEFAULT_HEIGHT / 2); var offsetX = core.clamp(centerX - core.__HALF_SIZE__, 0, width - core.__SIZE__),
var offsetX = core.clamp(centerX - halfWidth, 0, width - this.DEFAULT_WIDTH), offsetY = core.clamp(centerY - core.__HALF_SIZE__, 0, height - core.__SIZE__);
offsetY = core.clamp(centerY - halfHeight, 0, height - this.DEFAULT_HEIGHT); ctx.drawImage(tempCanvas.canvas, offsetX * 32, offsetY * 32, core.__PIXELS__, core.__PIXELS__, x, y, size, size);
ctx.drawImage(tempCanvas.canvas, offsetX * 32, offsetY * 32, this.DEFAULT_PIXEL_WIDTH, this.DEFAULT_PIXEL_HEIGHT, x, y, size, size);
} }
} }

View File

@ -8,10 +8,6 @@
function ui() { function ui() {
this._init(); this._init();
this.DEFAULT_WIDTH = 13;
this.DEFAULT_HEIGHT = 13;
this.DEFAULT_PIXEL_WIDTH = this.DEFAULT_WIDTH * 32;
this.DEFAULT_PIXEL_HEIGHT = this.DEFAULT_HEIGHT * 32;
} }
// 初始化UI // 初始化UI
@ -1651,9 +1647,8 @@ ui.prototype.drawCenterFly = function () {
var toX = core.bigmap.width - 1 - core.getHeroLoc('x'), toY = core.bigmap.height - 1 - core.getHeroLoc('y'); var toX = core.bigmap.width - 1 - core.getHeroLoc('x'), toY = core.bigmap.height - 1 - core.getHeroLoc('y');
core.drawThumbnail(null, null, {heroLoc: core.status.hero.loc, heroIcon: core.getFlag('heroIcon', "hero.png")}, core.drawThumbnail(null, null, {heroLoc: core.status.hero.loc, heroIcon: core.getFlag('heroIcon', "hero.png")},
{ctx: 'ui', centerX: toX, centerY: toY}); {ctx: 'ui', centerX: toX, centerY: toY});
var midX = Math.floor(this.DEFAULT_WIDTH / 2), midY = Math.floor(this.DEFAULT_HEIGHT / 2); var offsetX = core.clamp(toX - core.__HALF_SIZE__, 0, core.bigmap.width - core.__SIZE__),
var offsetX = core.clamp(toX - midX, 0, core.bigmap.width - this.DEFAULT_WIDTH), offsetY = core.clamp(toY - core.__HALF_SIZE__, 0, core.bigmap.height - core.__SIZE__);
offsetY = core.clamp(toY - midY, 0, core.bigmap.height - this.DEFAULT_HEIGHT);
core.fillRect('ui', (toX - offsetX) * 32, (toY - offsetY) * 32, 32, 32, fillstyle); core.fillRect('ui', (toX - offsetX) * 32, (toY - offsetY) * 32, 32, 32, fillstyle);
core.status.event.data = {"x": toX, "y": toY, "posX": toX - offsetX, "posY": toY - offsetY}; core.status.event.data = {"x": toX, "y": toY, "posX": toX - offsetX, "posY": toY - offsetY};
core.drawTip("请确认当前中心对称飞行器的位置"); core.drawTip("请确认当前中心对称飞行器的位置");