Commit 78a9a144 authored by rockyl's avatar rockyl

修复

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