Commit 78a9a144 authored by rockyl's avatar rockyl

修复

parent 6fd2ea06
...@@ -3260,8 +3260,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -3260,8 +3260,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return this.getChildByPath(pathArr, 'getChildByName'); return this.getChildByPath(pathArr, 'getChildByName');
}; };
Container.prototype.getChildByIndexPath = function (path) { Container.prototype.getChildByIndexPath = function (path) {
var pathArr = path.split('/').map(function (seg) { return parseInt(seg); }); if (path) {
return this.getChildByPath(pathArr, 'getChildAt'); var pathArr = path.split('/').map(function (seg) { return parseInt(seg); });
return this.getChildByPath(pathArr, 'getChildAt');
}
else {
return this;
}
}; };
Container.prototype.findChildByUUID = function (uuid) { Container.prototype.findChildByUUID = function (uuid) {
if (this['uuid'] === uuid) { if (this['uuid'] === uuid) {
...@@ -7897,7 +7902,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -7897,7 +7902,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var skipTagNames = ['INPUT']; var skipTagNames = ['INPUT'];
var Stage = (function (_super) { var Stage = (function (_super) {
tslib_1.__extends(Stage, _super); tslib_1.__extends(Stage, _super);
function Stage(rootDivId, desW, desH, frameRate, scaleMode, renderType, transparent, bgColor) { function Stage(rootDivId, desW, desH, frameRate, scaleMode, renderType, transparent, bgColor, autoResize) {
if (rootDivId === void 0) { rootDivId = "cusEngine"; } if (rootDivId === void 0) { rootDivId = "cusEngine"; }
if (desW === void 0) { desW = 750; } if (desW === void 0) { desW = 750; }
if (desH === void 0) { desH = 1206; } if (desH === void 0) { desH = 1206; }
...@@ -7906,6 +7911,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -7906,6 +7911,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (renderType === void 0) { renderType = exports.RENDERER_TYPE.WEBGL; } if (renderType === void 0) { renderType = exports.RENDERER_TYPE.WEBGL; }
if (transparent === void 0) { transparent = true; } if (transparent === void 0) { transparent = true; }
if (bgColor === void 0) { bgColor = 0x000000; } if (bgColor === void 0) { bgColor = 0x000000; }
if (autoResize === void 0) { autoResize = false; }
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
_this.iosTouchendPreventDefault = true; _this.iosTouchendPreventDefault = true;
_this.isPreventDefaultEvent = true; _this.isPreventDefaultEvent = true;
...@@ -7950,6 +7956,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -7950,6 +7956,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
s.rootDiv = div; s.rootDiv = div;
s.setFrameRate(frameRate); s.setFrameRate(frameRate);
s._scaleMode = scaleMode; s._scaleMode = scaleMode;
s.autoResize = autoResize;
var canvas = document.createElement("canvas"); var canvas = document.createElement("canvas");
s.rootDiv.appendChild(canvas); s.rootDiv.appendChild(canvas);
canvas.id = "cusCanvas"; canvas.id = "cusCanvas";
...@@ -8099,29 +8106,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -8099,29 +8106,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return 60 / (this._flush + 1); return 60 / (this._flush + 1);
}; };
Stage.prototype.getRootDivWH = function (div) { Stage.prototype.getRootDivWH = function (div) {
var sw = div.style.width; var divBound = div.getBoundingClientRect();
var sh = div.style.height; var w = divBound.width;
var iw = document.body.clientWidth; var h = divBound.height;
var ih = document.body.clientHeight; return { w: w, h: h };
var vW = parseInt(sw);
var vH = parseInt(sh);
if (vW.toString() == "NaN") {
vW = iw;
}
else {
if (sw.indexOf("%") > 0) {
vW *= iw / 100;
}
}
if (vH.toString() == "NaN") {
vH = ih;
}
else {
if (sh.indexOf("%") > 0) {
vH *= ih / 100;
}
}
return { w: vW, h: vH };
}; };
Stage.prototype.kill = function () { Stage.prototype.kill = function () {
Stage.removeUpdateObj(this); Stage.removeUpdateObj(this);
...@@ -20763,12 +20751,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20763,12 +20751,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
//# sourceMappingURL=auto-layout.js.map //# sourceMappingURL=auto-layout.js.map
var propPrefixFilter = ['_', '__', '$'];
var propTypeFilter = ['object', 'function'];
var EditorStage = (function (_super) { var EditorStage = (function (_super) {
tslib_1.__extends(EditorStage, _super); tslib_1.__extends(EditorStage, _super);
function EditorStage(stage) { function EditorStage(stage) {
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
_this.name = 'editor-stage'; _this.name = 'editor-stage';
_this.addEventListener('modify-props', _this.onModifyProps, _this);
return _this; return _this;
} }
EditorStage.prototype.launch = function (onStart) { EditorStage.prototype.launch = function (onStart) {
...@@ -20781,18 +20770,48 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20781,18 +20770,48 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var view = this._view = instantiate(viewConfig); var view = this._view = instantiate(viewConfig);
this.addChild(view); this.addChild(view);
}; };
EditorStage.prototype.getNodeProps = function (nodePath) { EditorStage.prototype.getNode = function (nodePath, origin) {
return this._view.getChildByIndexPath(nodePath); if (origin === void 0) { origin = false; }
};
EditorStage.prototype.onModifyProps = function (e) {
console.log(e.data);
var _a = e.data, nodePath = _a.nodePath, props = _a.props;
var node = this._view.getChildByIndexPath(nodePath); var node = this._view.getChildByIndexPath(nodePath);
if (node) {
if (origin) {
return node;
}
else {
var node2 = {};
for (var key in node) {
var pass = false;
for (var _i = 0, propPrefixFilter_1 = propPrefixFilter; _i < propPrefixFilter_1.length; _i++) {
var prefix = propPrefixFilter_1[_i];
if (key.indexOf(prefix) >= 0) {
pass = true;
break;
}
}
if (pass) {
continue;
}
var v = node[key];
if (propTypeFilter.indexOf(typeof v) < 0) {
node2[key] = v;
}
}
return node2;
}
}
};
EditorStage.prototype.resizeStage = function () {
this.stage.resize();
};
EditorStage.prototype.modifyProps = function (nodePath, props) {
var node = this.getNode(nodePath, true);
if (node) { if (node) {
injectProperties(node, props); injectProperties(node, props);
return true;
} }
else { else {
console.warn('node not found:', nodePath); console.warn('node not found:', nodePath);
return false;
} }
}; };
return EditorStage; return EditorStage;
...@@ -20834,9 +20853,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20834,9 +20853,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
case 1: case 1:
_a.sent(); _a.sent();
return [4, new Promise(function (resolve) { 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, _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;
exports.editorMode = _editorMode; exports.editorMode = _editorMode;
var stage = window['stage'] = new Stage(containerId || "game-container", designWidth || 750, designHeight || 1334, frameRate || 60, scaleMode || StageScaleMode.FIXED_WIDTH, rendererType || exports.RENDERER_TYPE.WEBGL); 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); initAutoLayout(stage);
Stage.flushAll(); Stage.flushAll();
stage.addEventListener(Event.ON_INIT_STAGE, function () { stage.addEventListener(Event.ON_INIT_STAGE, function () {
......
This diff is collapsed.
...@@ -270,8 +270,12 @@ export default class Container extends DisplayObject { ...@@ -270,8 +270,12 @@ export default class Container extends DisplayObject {
* @param path * @param path
*/ */
getChildByIndexPath(path: string): DisplayObject { getChildByIndexPath(path: string): DisplayObject {
const pathArr = path.split('/').map(seg => parseInt(seg)); if (path) {
return this.getChildByPath(pathArr, 'getChildAt'); const pathArr = path.split('/').map(seg => parseInt(seg));
return this.getChildByPath(pathArr, 'getChildAt');
} else {
return this;
}
} }
/** /**
...@@ -488,7 +492,7 @@ export default class Container extends DisplayObject { ...@@ -488,7 +492,7 @@ export default class Container extends DisplayObject {
this._bounds.height = this._height; this._bounds.height = this._height;
}*/ }*/
if(widthSetted || heightSetted){ if (widthSetted || heightSetted) {
const rect = this._localBoundsSelf; const rect = this._localBoundsSelf;
var matrix = this.transform.worldMatrix; var matrix = this.transform.worldMatrix;
matrix.transformPoint(rect.x, rect.y, DisplayObject._p1); matrix.transformPoint(rect.x, rect.y, DisplayObject._p1);
...@@ -507,7 +511,7 @@ export default class Container extends DisplayObject { ...@@ -507,7 +511,7 @@ export default class Container extends DisplayObject {
//如果不可见 //如果不可见
if (!this.visible) return null if (!this.visible) return null
//如果禁止子级的鼠标事件 //如果禁止子级的鼠标事件
if (isMouseEvent && !this.mouseChildren){ if (isMouseEvent && !this.mouseChildren) {
return this.hitTestSelf(globalPoint); return this.hitTestSelf(globalPoint);
} }
var children = this.children; var children = this.children;
......
...@@ -349,6 +349,7 @@ export class Stage extends Container { ...@@ -349,6 +349,7 @@ export class Stage extends Container {
* @param {number} renderType 渲染类型2canvas * @param {number} renderType 渲染类型2canvas
* @param {boolean} transparent 透明否,默认透明true,此时bgColor无效 * @param {boolean} transparent 透明否,默认透明true,此时bgColor无效
* @param {number} bgColor 背景颜色十六进制 * @param {number} bgColor 背景颜色十六进制
* @param autoResize 是否自动重置尺寸
* @public * @public
* @since 1.0.0 * @since 1.0.0
*/ */
...@@ -360,7 +361,8 @@ export class Stage extends Container { ...@@ -360,7 +361,8 @@ export class Stage extends Container {
scaleMode: string = StageScaleMode.FIXED_WIDTH, scaleMode: string = StageScaleMode.FIXED_WIDTH,
renderType: RENDERER_TYPE = RENDERER_TYPE.WEBGL, renderType: RENDERER_TYPE = RENDERER_TYPE.WEBGL,
transparent: boolean = true, transparent: boolean = true,
bgColor: number = 0x000000 bgColor: number = 0x000000,
autoResize: boolean = false,
) { ) {
super(); super();
let s: Stage = this; let s: Stage = this;
...@@ -376,6 +378,7 @@ export class Stage extends Container { ...@@ -376,6 +378,7 @@ export class Stage extends Container {
s.rootDiv = div; s.rootDiv = div;
s.setFrameRate(frameRate); s.setFrameRate(frameRate);
s._scaleMode = scaleMode; s._scaleMode = scaleMode;
s.autoResize = autoResize;
//s.anchorX = desW >> 1; //s.anchorX = desW >> 1;
//s.anchorY = desH >> 1; //s.anchorY = desH >> 1;
...@@ -556,9 +559,7 @@ export class Stage extends Container { ...@@ -556,9 +559,7 @@ export class Stage extends Container {
* @return {{w: number, h: number}} * @return {{w: number, h: number}}
*/ */
public getRootDivWH(div: HTMLDivElement) { public getRootDivWH(div: HTMLDivElement) {
let sw = div.style.width; /*let iw = document.body.clientWidth;
let sh = div.style.height;
let iw = document.body.clientWidth;
// let ih = document.body.clientHeight-40; // let ih = document.body.clientHeight-40;
let ih = document.body.clientHeight; let ih = document.body.clientHeight;
let vW = parseInt(sw); let vW = parseInt(sw);
...@@ -577,7 +578,11 @@ export class Stage extends Container { ...@@ -577,7 +578,11 @@ export class Stage extends Container {
vH *= ih / 100; vH *= ih / 100;
} }
} }
return {w: vW, h: vH}; return {w: vW, h: vH};*/
let divBound = div.getBoundingClientRect();
let w = divBound.width;
let h = divBound.height;
return {w, h};
} }
/** /**
......
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
import {Stage} from "../../2d/display/index"; import {Stage} from "../../2d/display/index";
import {Node} from "./nodes/Node"; import {Node} from "./nodes/Node";
import {instantiate} from "./view-interpreter"; import {instantiate} from "./view-interpreter";
import {injectProperties} from "../utils/utils"; import {injectProperties, objClone} from "../utils/utils";
const propPrefixFilter = ['_', '__', '$'];
const propTypeFilter = ['object', 'function'];
/** /**
* 编辑器舞台 * 编辑器舞台
...@@ -17,8 +20,6 @@ export class EditorStage extends Node { ...@@ -17,8 +20,6 @@ export class EditorStage extends Node {
super(); super();
this.name = 'editor-stage'; this.name = 'editor-stage';
this.addEventListener('modify-props', this.onModifyProps, this);
} }
launch(onStart) { launch(onStart) {
...@@ -33,19 +34,47 @@ export class EditorStage extends Node { ...@@ -33,19 +34,47 @@ export class EditorStage extends Node {
this.addChild(view); this.addChild(view);
} }
getNodeProps(nodePath) { getNode(nodePath, origin = false): any {
return this._view.getChildByIndexPath(nodePath); let node = this._view.getChildByIndexPath(nodePath);
if (node) {
if(origin){
return node;
}else{
let node2 = {};
for (let key in node) {
let pass = false;
for (let prefix of propPrefixFilter) {
if (key.indexOf(prefix) >= 0) {
pass = true;
break;
}
}
if (pass) {
continue;
}
let v = node[key];
if (propTypeFilter.indexOf(typeof v) < 0) {
node2[key] = v;
}
}
return node2;
}
}
}
resizeStage() {
this.stage.resize();
} }
private onModifyProps(e) { modifyProps(nodePath, props) {
console.log(e.data); let node = this.getNode(nodePath, true);
const {nodePath, props} = e.data;
let node = this._view.getChildByIndexPath(nodePath);
if (node) { if (node) {
injectProperties(node, props); injectProperties(node, props);
return true;
} else { } else {
console.warn('node not found:', nodePath); console.warn('node not found:', nodePath);
return false;
} }
} }
} }
...@@ -55,7 +55,7 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) { ...@@ -55,7 +55,7 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
setTimeout(resolve, 300); setTimeout(resolve, 300);
}); });
return await new Promise(resolve => { return await new Promise(resolve => {
const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType, editorMode: _editorMode,} = config.options; const {containerId, designWidth, designHeight, frameRate, scaleMode, rendererType, bgColor, autoResize, editorMode: _editorMode,} = config.options;
editorMode = _editorMode; editorMode = _editorMode;
let stage = window['stage'] = new Stage( let stage = window['stage'] = new Stage(
...@@ -65,6 +65,9 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) { ...@@ -65,6 +65,9 @@ export async function launchWithConfig(config, loadingDelegate?, onStart?) {
frameRate || 60, frameRate || 60,
scaleMode || StageScaleMode.FIXED_WIDTH, scaleMode || StageScaleMode.FIXED_WIDTH,
rendererType || RENDERER_TYPE.WEBGL, rendererType || RENDERER_TYPE.WEBGL,
true,
bgColor,
autoResize,
); );
initAutoLayout(stage); initAutoLayout(stage);
Stage.flushAll(); Stage.flushAll();
......
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