Commit dcdb6f57 authored by rockyl's avatar rockyl

设计时适配

parent 78a9a144
......@@ -3268,6 +3268,20 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return this;
}
};
Container.prototype.getIndexPath = function (untilNode) {
untilNode = untilNode || this.stage;
var node = this;
var path = [];
while (node.parent) {
var child = node;
node = node.parent;
path.unshift(node.getChildIndex(child));
if (node === untilNode) {
break;
}
}
return path.join('/');
};
Container.prototype.findChildByUUID = function (uuid) {
if (this['uuid'] === uuid) {
return this;
......@@ -18992,6 +19006,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (url.indexOf('://') >= 0) {
if (url.indexOf(assetScheme) === 0) {
url = url.replace(assetScheme, '');
if (exports.editorMode) {
url = exports.assetResolver(url);
}
}
}
else {
......@@ -20757,7 +20774,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
tslib_1.__extends(EditorStage, _super);
function EditorStage(stage) {
var _this = _super.call(this) || this;
_this._pos = new Point();
_this.name = 'editor-stage';
_this.percentWidth = 100;
_this.percentHeight = 100;
return _this;
}
EditorStage.prototype.launch = function (onStart) {
......@@ -20807,6 +20827,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var node = this.getNode(nodePath, true);
if (node) {
injectProperties(node, props);
node.adjustProxy.adjustLayout();
return true;
}
else {
......@@ -20814,6 +20835,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return false;
}
};
EditorStage.prototype.getNodeWithPos = function (pos) {
var globalPos = this.stage.globalToLocal(pos, this._pos);
globalPos.x *= devicePixelRatio;
globalPos.y *= devicePixelRatio;
var node = this.hitTestPoint(globalPos, true);
return node;
};
return EditorStage;
}(Node$1));
......@@ -20853,8 +20881,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
case 1:
_a.sent();
return [4, new Promise(function (resolve) {
var _a = config.options, containerId = _a.containerId, designWidth = _a.designWidth, designHeight = _a.designHeight, frameRate = _a.frameRate, scaleMode = _a.scaleMode, rendererType = _a.rendererType, bgColor = _a.bgColor, autoResize = _a.autoResize, _editorMode = _a.editorMode;
var _a = config.options, containerId = _a.containerId, designWidth = _a.designWidth, designHeight = _a.designHeight, frameRate = _a.frameRate, scaleMode = _a.scaleMode, rendererType = _a.rendererType, bgColor = _a.bgColor, autoResize = _a.autoResize, _editorMode = _a.editorMode, _assetResolver = _a.assetResolver;
exports.editorMode = _editorMode;
exports.assetResolver = _assetResolver;
var stage = window['stage'] = new Stage(containerId || "game-container", designWidth || 750, designHeight || 1334, frameRate || 60, scaleMode || StageScaleMode.FIXED_WIDTH, rendererType || exports.RENDERER_TYPE.WEBGL, true, bgColor, autoResize);
initAutoLayout(stage);
Stage.flushAll();
......
This diff is collapsed.
{"id":"engine","url":"engine.d2f4eafa108b00ed5ac00e2d30ee98f8af4a9118.js"}
\ No newline at end of file
{"id":"engine","url":"engine.50767b1fe652a3daf7f557e5cfb9eaa6090fc805.js"}
\ No newline at end of file
......@@ -278,6 +278,24 @@ export default class Container extends DisplayObject {
}
}
/**
* 获取索引路径
*/
getIndexPath(untilNode?): string {
untilNode = untilNode || this.stage;
let node = this;
let path = [];
while (node.parent) {
let child = node;
node = node.parent;
path.unshift(node.getChildIndex(child));
if (node === untilNode) {
break;
}
}
return path.join('/');
}
/**
* 根据uuid搜索子节点
* @param uuid
......
......@@ -6,6 +6,8 @@ import {Stage} from "../../2d/display/index";
import {Node} from "./nodes/Node";
import {instantiate} from "./view-interpreter";
import {injectProperties, objClone} from "../utils/utils";
import {devicePixelRatio} from "../../2d/const";
import {Point} from "../../2d/math/Point";
const propPrefixFilter = ['_', '__', '$'];
const propTypeFilter = ['object', 'function'];
......@@ -20,6 +22,9 @@ export class EditorStage extends Node {
super();
this.name = 'editor-stage';
this.percentWidth = 100;
this.percentHeight = 100;
}
launch(onStart) {
......@@ -37,9 +42,9 @@ export class EditorStage extends Node {
getNode(nodePath, origin = false): any {
let node = this._view.getChildByIndexPath(nodePath);
if (node) {
if(origin){
if (origin) {
return node;
}else{
} else {
let node2 = {};
for (let key in node) {
let pass = false;
......@@ -71,10 +76,24 @@ export class EditorStage extends Node {
if (node) {
injectProperties(node, props);
node.adjustProxy.adjustLayout();
return true;
} else {
console.warn('node not found:', nodePath);
return false;
}
}
private _pos = new Point();
getNodeWithPos(pos) {
let globalPos: any = this.stage.globalToLocal(pos, this._pos);
globalPos.x *= devicePixelRatio;
globalPos.y *= devicePixelRatio;
let node = this.hitTestPoint(globalPos, true);
//console.log(globalPos.x, globalPos.y, node ? node.name : '');
return node;
}
}
......@@ -9,6 +9,7 @@ import {ESCAPE_REG_EXP} from "../../utils/index";
import {Event} from "../../../2d/events/index";
import {Container} from "../../../2d/display/index";
import {IUIComponent} from "./IUIComponent";
import {assetResolver, editorMode} from "../../launcher";
const assetScheme = 'asset://';
......@@ -36,21 +37,25 @@ export class Image extends Sprite implements IUIComponent {
private updateSource() {
let url = this._source;
if (url) {
if (url.indexOf('://') >= 0) { //如果是有协议的地址
if (url.indexOf(assetScheme) === 0) {
url = url.replace(assetScheme, '');
/*const assetConfig = getAssetByUUID(uuid);
if(assetConfig){
url = assetConfig.url;
this.texture = Texture.fromImage(url);
}*/
}
} else { //否则就使用素材名
const assetConfig = getAssetByName(url);
if (assetConfig) {
url = assetConfig.uuid;
if (url.indexOf('://') >= 0) { //如果是有协议的地址
if (url.indexOf(assetScheme) === 0) {
url = url.replace(assetScheme, '');
/*const assetConfig = getAssetByUUID(uuid);
if(assetConfig){
url = assetConfig.url;
this.texture = Texture.fromImage(url);
}*/
if (editorMode) {
url = assetResolver(url);
}
}
} else { //否则就使用素材名
const assetConfig = getAssetByName(url);
if (assetConfig) {
url = assetConfig.uuid;
}
}
}
this.texture = Texture.fromImage(url, this.crossOrigin);
} else {
this.texture = null;
......
......@@ -17,6 +17,7 @@ export let gameStage: GameStage;
export let editorStage: EditorStage;
export let editorMode = false;
export let assetResolver;
export function launch(url, loadingDelegate?, onStart?) {
if (queryParams.__proxy_mode__) {
......@@ -55,8 +56,9 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
setTimeout(resolve, 300);
});
return await new Promise(resolve => {
const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType, bgColor, autoResize, editorMode: _editorMode,} = config.options;
const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType, bgColor, autoResize, editorMode: _editorMode, assetResolver: _assetResolver} = config.options;
editorMode = _editorMode;
assetResolver = _assetResolver;
let stage = window['stage'] = new Stage(
containerId || "game-container",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment