Commit 3088fd51 authored by rockyl's avatar rockyl

Merge branch 'res-group' into dev

# Conflicts:
#	src/zeroing/game-warpper/GameStage.ts
#	src/zeroing/game-warpper/StackContainer.ts
#	src/zeroing/game-warpper/assets-manager.ts
parents fecd5a63 711d9001
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/zeroing-engine.iml" filepath="$PROJECT_DIR$/.idea/zeroing-engine.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="af35c04f-08f6-48ed-85db-2f94c60e87fd" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="JavaScript File" />
<option value="MarkDown" />
<option value="TypeScript File" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="dev" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="UPDATE_TYPE" value="MERGE" />
</component>
<component name="IgnoredFileRootStore">
<option name="generatedRoots">
<set>
<option value="$PROJECT_DIR$/.idea" />
</set>
</option>
</component>
<component name="ProjectId" id="1ZYzLmPKm3UfhIZLkr8RtiZwhUf" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/zeroing/game-warpper/mvvm" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="yarn" />
<property name="run.code.analysis.last.selected.profile" value="pProject Default" />
<property name="settings.editor.selected.configurable" value="settings.typescriptcompiler" />
<property name="ts.external.directory.path" value="$PROJECT_DIR$/node_modules/typescript/lib" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/zeroing/game-warpper/mvvm" />
<recent name="$PROJECT_DIR$/book/engine" />
</key>
</component>
<component name="RunManager" selected="npm.dev">
<configuration name="build:prod" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="build:prod" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
<configuration name="debug" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="debug" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
<configuration name="declare" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="declare" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
<configuration name="dev" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="dev" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
<configuration name="preprocess" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="preprocess" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="npm.preprocess" />
<item itemvalue="npm.dev" />
<item itemvalue="npm.declare" />
<item itemvalue="npm.debug" />
<item itemvalue="npm.build:prod" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="af35c04f-08f6-48ed-85db-2f94c60e87fd" name="Default Changelist" comment="" />
<created>1585030761378</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1585030761378</updated>
<workItem from="1585030763664" duration="83000" />
<workItem from="1585309307077" duration="223000" />
<workItem from="1585532868135" duration="9432000" />
<workItem from="1585548073784" duration="13304000" />
<workItem from="1585619020647" duration="19493000" />
<workItem from="1585705357868" duration="3415000" />
<workItem from="1585809744255" duration="3460000" />
<workItem from="1585879466515" duration="16665000" />
<workItem from="1586224104828" duration="8506000" />
<workItem from="1586414881820" duration="3996000" />
<workItem from="1586488052078" duration="2983000" />
<workItem from="1586508741055" duration="875000" />
<workItem from="1586512194603" duration="17000" />
<workItem from="1586512428197" duration="1078000" />
<workItem from="1586750167354" duration="1386000" />
<workItem from="1586832966354" duration="17259000" />
<workItem from="1586915131468" duration="17366000" />
<workItem from="1586970547836" duration="4000" />
<workItem from="1587001399822" duration="2758000" />
<workItem from="1587006105423" duration="3040000" />
<workItem from="1587037618949" duration="599000" />
<workItem from="1587088026702" duration="14465000" />
<workItem from="1587193648244" duration="11740000" />
<workItem from="1587224345938" duration="141000" />
<workItem from="1587355049281" duration="1821000" />
<workItem from="1587452856105" duration="175000" />
<workItem from="1587520357116" duration="17507000" />
<workItem from="1587606248943" duration="80000" />
<workItem from="1587606438033" duration="14026000" />
<workItem from="1587696728690" duration="5561000" />
<workItem from="1587713741312" duration="310000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
<option name="exactExcludedFiles">
<list>
<option value="$PROJECT_DIR$/examples/scripts/Wave.js" />
<option value="$PROJECT_DIR$/examples/scripts/TouchZoom.js" />
</list>
</option>
</component>
<component name="WindowStateProjectService">
<state x="2240" y="25" key="#Inspections" timestamp="1585534766890">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2240" y="25" key="#Inspections/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1585534766890" />
<state x="2286" y="133" key="#com.intellij.ide.fileTemplates.ui.ConfigureTemplatesDialog" timestamp="1585624499558">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2286" y="133" key="#com.intellij.ide.fileTemplates.ui.ConfigureTemplatesDialog/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1585624499558" />
<state x="2357" y="62" key="#debug" timestamp="1585904539137">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2357" y="62" key="#debug/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1585904539137" />
<state x="2391" y="221" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1" timestamp="1585563378350">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2391" y="221" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1585563378350" />
<state width="969" height="466" key="DebuggerActiveHint" timestamp="1585535223173">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state width="969" height="466" key="DebuggerActiveHint/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1585535223173" />
<state width="584" height="1056" key="GridCell.Tab.0.bottom" timestamp="1587713730150">
<screen x="1680" y="-252" width="1920" height="1200" />
</state>
<state width="276" height="1101" key="GridCell.Tab.0.bottom/0.0.1680.1050/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587712516387" />
<state width="584" height="1056" key="GridCell.Tab.0.bottom/0.23.1680.1027/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587713730150" />
<state width="584" height="1056" key="GridCell.Tab.0.bottom/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587710590931" />
<state width="336" height="906" key="GridCell.Tab.0.bottom/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1585720951511" />
<state width="427" height="906" key="GridCell.Tab.0.bottom/35.23.1645.1027@35.23.1645.1027" timestamp="1586963282147" />
<state width="584" height="1056" key="GridCell.Tab.0.center" timestamp="1587713730146">
<screen x="1680" y="-252" width="1920" height="1200" />
</state>
<state width="276" height="1101" key="GridCell.Tab.0.center/0.0.1680.1050/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587712516380" />
<state width="584" height="1056" key="GridCell.Tab.0.center/0.23.1680.1027/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587713730146" />
<state width="584" height="1056" key="GridCell.Tab.0.center/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587710590929" />
<state width="336" height="906" key="GridCell.Tab.0.center/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1585720951508" />
<state width="427" height="906" key="GridCell.Tab.0.center/35.23.1645.1027@35.23.1645.1027" timestamp="1586963282146" />
<state width="584" height="1056" key="GridCell.Tab.0.left" timestamp="1587713730145">
<screen x="1680" y="-252" width="1920" height="1200" />
</state>
<state width="276" height="1101" key="GridCell.Tab.0.left/0.0.1680.1050/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587712516377" />
<state width="584" height="1056" key="GridCell.Tab.0.left/0.23.1680.1027/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587713730145" />
<state width="584" height="1056" key="GridCell.Tab.0.left/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587710590928" />
<state width="336" height="906" key="GridCell.Tab.0.left/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1585720951505" />
<state width="427" height="906" key="GridCell.Tab.0.left/35.23.1645.1027@35.23.1645.1027" timestamp="1586963282146" />
<state width="584" height="1056" key="GridCell.Tab.0.right" timestamp="1587713730146">
<screen x="1680" y="-252" width="1920" height="1200" />
</state>
<state width="276" height="1101" key="GridCell.Tab.0.right/0.0.1680.1050/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587712516385" />
<state width="584" height="1056" key="GridCell.Tab.0.right/0.23.1680.1027/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587713730146" />
<state width="584" height="1056" key="GridCell.Tab.0.right/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587710590930" />
<state width="336" height="906" key="GridCell.Tab.0.right/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1585720951509" />
<state width="427" height="906" key="GridCell.Tab.0.right/35.23.1645.1027@35.23.1645.1027" timestamp="1586963282147" />
<state x="445" y="278" key="IDE.errors.dialog" timestamp="1585719736587">
<screen x="35" y="23" width="1645" height="1027" />
</state>
<state x="445" y="278" key="IDE.errors.dialog/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1585719736587" />
<state x="2356" y="82" key="MultipleFileMergeDialog" timestamp="1586919094159">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2356" y="82" key="MultipleFileMergeDialog/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1586919094159" />
<state x="2149" y="-2" key="SettingsEditor" timestamp="1585555176349">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2149" y="-2" key="SettingsEditor/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1585555176349" />
<state x="2441" y="283" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1587713822207">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2441" y="270" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2/0.0.1680.1050/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587713656947" />
<state x="2441" y="283" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587713822207" />
<state x="2410" y="78" key="git4idea.branch.GitSmartOperationDialog" timestamp="1587713818098">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2410" y="78" key="git4idea.branch.GitSmartOperationDialog/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587713818098" />
<state x="660" y="291" key="git4idea.branch.GitSmartOperationDialog/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1585818702345" />
<state x="2327" y="157" key="git4idea.merge.GitPullDialog" timestamp="1587714144888">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2327" y="157" key="git4idea.merge.GitPullDialog/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587714144888" />
<state x="2305" y="18" width="670" height="690" key="search.everywhere.popup" timestamp="1587713287518">
<screen x="1680" y="-252" width="1920" height="1200" />
</state>
<state x="2305" y="18" width="670" height="690" key="search.everywhere.popup/0.0.1680.1050/1680.-252.1920.1200@1680.-252.1920.1200" timestamp="1587713287518" />
<state x="2305" y="36" width="670" height="676" key="search.everywhere.popup/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1587712362381" />
<state x="570" y="254" width="670" height="590" key="search.everywhere.popup/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1587004990635" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
......@@ -1261,6 +1261,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var bounds = this.getBounds(false, rect);
this.parent = parentRef;
this.transform = transformRef;
if (this.parent && this.stage) {
this.updateTransform();
}
return bounds;
};
DisplayObject.prototype.calculateBounds = function () {
......@@ -1776,7 +1779,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
function objClone(obj) {
return JSON.parse(JSON.stringify(obj));
return obj ? JSON.parse(JSON.stringify(obj)) : obj;
}
var percentKeys = ['width', 'height'];
function propertyParse(key, node, properties) {
......@@ -2641,10 +2644,11 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
Process.prototype.execute = function (args) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var metaConfig, meta, result, p, i, li, key, scriptResult, subProcessResult;
var payload, metaConfig, meta, result, p, i, li, key, scriptResult, subProcessResult;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
payload = objClone(args);
metaConfig = this._config.meta;
if (metaConfig) {
this._meta = meta = this.getProcessMeta(metaConfig);
......@@ -2661,7 +2665,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
case 1:
if (!(i < li)) return [3, 5];
key = meta.output[i];
p = this._executeNextProcess(key, args);
p = this._executeNextProcess(key, payload);
if (!(i === li - 1)) return [3, 3];
return [4, p];
case 2:
......@@ -2676,7 +2680,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
i++;
return [3, 1];
case 5: return [3, 12];
case 6: return [4, this._executeMetaScript('', args, metaConfig)];
case 6: return [4, this._executeMetaScript('', payload, metaConfig)];
case 7:
scriptResult = _a.sent();
subProcessResult = void 0;
......@@ -3375,24 +3379,27 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Rectangle.createFromRects(this._bounds, child._bounds);
}
}
};
Container.prototype._calculateBounds = function () {
var widthSetted = !!this._width && this._width !== 0;
var heightSetted = !!this._height && this._height !== 0;
if (widthSetted) {
this._bounds.width = this._width;
}
if (heightSetted) {
this._bounds.height = this._height;
if (widthSetted || heightSetted) {
var rect = this._localBoundsSelf;
var matrix = this.transform.worldMatrix;
matrix.transformPoint(rect.x, rect.y, DisplayObject._p1);
matrix.transformPoint(rect.x + rect.width, rect.y, DisplayObject._p2);
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
}
};
Container.prototype._calculateBounds = function () {
};
Container.prototype.hitTestPoint = function (globalPoint, isMouseEvent) {
if (isMouseEvent === void 0) { isMouseEvent = false; }
if (!this.visible)
return null;
var result = this.hitTestSelf(globalPoint);
if (isMouseEvent && !this.mouseChildren)
return result;
if (isMouseEvent && !this.mouseChildren) {
return this.hitTestSelf(globalPoint);
}
var children = this.children;
var length = children.length;
var child, hitDisplayObject;
......@@ -3406,7 +3413,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (hitDisplayObject)
return hitDisplayObject;
}
return this.hitTestSelf(globalPoint);
return this.displayObjectHitTestPoint(globalPoint, isMouseEvent);
};
Container.prototype.hitTestSelf = function (globalPoint) {
if (this.mouseEnabled) {
......@@ -3415,8 +3422,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return null;
};
Container.prototype.hitTestSelfBounds = function (globalPoint) {
if (this.width && this.height) {
var _a = this.getBounds(), tx = _a.x, ty = _a.y;
if (this._width && this._height) {
var _a = this.worldMatrix, tx = _a.tx, ty = _a.ty;
var x = globalPoint.x, y = globalPoint.y;
if (x > tx &&
x < tx + this.width &&
......@@ -3507,6 +3514,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
set: function (value) {
if (this._width !== value) {
this._width = value;
this._localBoundsSelf.width = value;
this.dispatchEvent(Event.RESIZE);
}
},
......@@ -3520,6 +3528,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
set: function (value) {
if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
this.dispatchEvent(Event.RESIZE);
}
},
......@@ -5493,7 +5502,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
startTime: 0
};
function isWebGLSupported() {
var contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true };
var contextOptions = { stencil: true };
try {
if (!window["WebGLRenderingContext"]) {
return false;
......@@ -7817,7 +7826,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; }
......@@ -7826,6 +7835,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;
......@@ -7870,6 +7880,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";
......@@ -8019,29 +8030,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);
......@@ -10341,6 +10333,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
else {
this._texture.baseTexture.update();
}
this._texture.onBaseTextureUpdated({ target: this._texture.baseTexture });
this.offsetX = bounds.x;
this.offsetY = bounds.y;
return this._texture;
......@@ -10992,28 +10985,24 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var arr = item.split('=');
queryParams[arr[0]] = arr.length === 1 ? true : arr[1];
}
if (queryParams.appID) {
env.appID = queryParams.appID;
}
if (queryParams.channelType) {
env.channelType = queryParams.channelType;
}
if (queryParams.projectID) {
env.projectID = queryParams.projectID;
}
else if (window.location.pathname.match(new RegExp("/projectx/(\\S+)/index(\\S+)", "g"))) {
env.projectID = window.location.pathname.replace(new RegExp("/projectx/(\\S+)/index(\\S+)", "g"), "$1");
}
exports.newUser = true;
var key = 'nu_' + env.appID + '_' + env.projectID;
var v = localStorage.getItem(key);
if (v) {
exports.newUser = false;
}
else {
localStorage.setItem(key, '1');
function appendScript(script, parent) {
if (parent === void 0) { parent = document.body; }
if (!script) {
return;
}
var scriptContent;
if (script.indexOf('<script') === 0) {
var temp = document.createElement('div');
temp.innerHTML = script;
scriptContent = temp.children[0].innerHTML;
}
else {
scriptContent = script;
}
var scriptEl = document.createElement('script');
scriptEl.innerHTML = scriptContent;
parent.appendChild(scriptEl);
}
console.log(exports.newUser);
function httpRequest(url, method, params, type, headers) {
if (method === void 0) { method = 'get'; }
......@@ -11257,7 +11246,109 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
'.mp3': 'Sound',
'': 'Raw',
};
function loadAssetGroup(config, onProgress, onComplete) {
var assetGroupLoaded = {};
var assetGroupLoading = {};
function checkAssetGroupLoaded(groupName) {
return assetGroupLoaded[groupName];
}
function loadAssetsGroups(groups, onStart, onFinish) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var total, loaded, groupName, depAssets, _a, _b, _c, _i, groupName, depAssets, _d;
return tslib_1.__generator(this, function (_e) {
switch (_e.label) {
case 0:
total = 0;
loaded = 0;
for (groupName in groups) {
if (!checkAssetGroupLoaded(groupName)) {
depAssets = groups[groupName];
if (depAssets && depAssets.length > 0) {
total += depAssets.length;
}
}
}
_a = onStart;
if (!_a) return [3, 2];
return [4, onStart()];
case 1:
_a = (_e.sent());
_e.label = 2;
case 2:
_b = [];
for (_c in groups)
_b.push(_c);
_i = 0;
_e.label = 3;
case 3:
if (!(_i < _b.length)) return [3, 6];
groupName = _b[_i];
if (!!checkAssetGroupLoaded(groupName)) return [3, 5];
depAssets = groups[groupName];
if (!(depAssets && depAssets.length > 0)) return [3, 5];
return [4, loadAssetsGroup(depAssets, groupName, function () {
loaded++;
globalEvent.dispatchEvent('load-assets-process', { loaded: loaded, total: total });
}, function () {
globalEvent.dispatchEvent('load-assets-complete');
})];
case 4:
_e.sent();
_e.label = 5;
case 5:
_i++;
return [3, 3];
case 6: return [4, new Promise(function (resolve) {
setTimeout(resolve, 100);
})];
case 7:
_e.sent();
_d = onFinish;
if (!_d) return [3, 9];
return [4, onFinish()];
case 8:
_d = (_e.sent());
_e.label = 9;
case 9:
return [2];
}
});
});
}
function loadAssetsGroup(config, groupName, onProcess, onComplete) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _i, _a, p;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
if (checkAssetGroupLoaded[groupName]) {
return [2];
}
if (assetGroupLoading[groupName]) {
return [2, new Promise(function (resolve, reject) {
assetGroupLoading[groupName].push({ resolve: resolve, reject: reject });
})];
}
else {
assetGroupLoading[groupName] = [];
}
return [4, loadAssets(config, onProcess, onComplete)];
case 1:
_b.sent();
assetGroupLoaded[groupName] = true;
for (_i = 0, _a = assetGroupLoading[groupName]; _i < _a.length; _i++) {
p = _a[_i];
p.resolve();
}
delete assetGroupLoading[groupName];
return [2];
}
});
});
}
function loadAssets(config, onProgress, onComplete) {
if (!config) {
console.log();
}
var total = config.length;
var loaded = 0;
var failedList = [];
......@@ -14635,7 +14726,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}(EventDispatcher));
var globalLoader = new Loader();
var padding$1 = 10;
var padding$1 = 50;
var styleFields = {
color: 'fillStyle',
stroke: 'lineWidth',
strokeColor: 'strokeStyle',
font: 'font',
};
var TextField = (function (_super) {
tslib_1.__extends(TextField, _super);
function TextField() {
......@@ -14643,10 +14740,11 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this._textAlpha = 1;
_this._textAlign = exports.TEXT_ALIGN.LEFT;
_this._verticalAlign = exports.VERTICAL_ALIGN.UP;
_this._lineSpacing = 14;
_this._lineSpacing = 0;
_this._lineType = exports.TEXT_lINETYPE.SINGLE;
_this._text = "";
_this._pureText = '';
_this._styleCache = [];
_this._font = "Arial";
_this._size = 12;
_this._fillColor = "#000";
......@@ -14655,6 +14753,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this._italic = false;
_this._bold = false;
_this._border = false;
_this._shadowColor = '#000';
_this._shadowBlur = 0;
_this._shadowOffset = new ObservablePoint(_this.onShadowOffsetChange, _this);
_this.realLines = [];
_this._instanceType = "TextFieldNode";
var canvas = document.createElement('canvas');
......@@ -14792,6 +14893,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
set: function (value) {
this._textFlow = value;
this.dirty = true;
this._styleCache.splice(0);
var text = '';
for (var _i = 0, _a = this._textFlow; _i < _a.length; _i++) {
var item = _a[_i];
......@@ -14820,6 +14922,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (!this.textFlow) {
return null;
}
if (this._styleCache[index]) {
return this._styleCache[index];
}
var targetItem;
var count = 0;
for (var _i = 0, _a = this._textFlow; _i < _a.length; _i++) {
......@@ -14830,6 +14935,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
break;
}
}
if (targetItem && targetItem.style) {
this._styleCache[index] = targetItem.style;
}
return targetItem.style;
};
Object.defineProperty(TextField.prototype, "font", {
......@@ -14936,20 +15044,85 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true,
configurable: true
});
Object.defineProperty(TextField.prototype, "shadowColor", {
get: function () {
return this._shadowColor;
},
set: function (value) {
if (this._shadowColor != value) {
this._shadowColor = value;
this.dirty = true;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextField.prototype, "shadowBlur", {
get: function () {
return this._shadowBlur;
},
set: function (value) {
if (this._shadowBlur != value) {
this._shadowBlur = value;
this.dirty = true;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextField.prototype, "shadowOffset", {
get: function () {
return this._shadowOffset;
},
set: function (value) {
if (this._shadowOffset != value) {
this._shadowOffset = value;
this.dirty = true;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextField.prototype, "shadowOffsetX", {
get: function () {
return this.position.x;
},
set: function (value) {
this._shadowOffset.x = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TextField.prototype, "shadowOffsetY", {
get: function () {
return this.position.y;
},
set: function (value) {
this._shadowOffset.y = value;
},
enumerable: true,
configurable: true
});
TextField.prototype.onShadowOffsetChange = function () {
this.dirty = true;
};
TextField.prototype._setupFont = function (font, size, bold, italic) {
var fontStyle = size;
fontStyle += "px ";
fontStyle += font;
if (bold) {
fontStyle = "bold " + fontStyle;
}
if (italic) {
fontStyle = "italic " + fontStyle;
}
return fontStyle;
};
TextField.prototype._prepContext = function (ctx) {
var s = this;
var font = s.size || 12;
font += "px ";
font += s.font;
if (s._bold) {
font = "bold " + font;
}
if (s._italic) {
font = "italic " + font;
}
ctx.font = font;
ctx.textAlign = s._textAlign || exports.TEXT_ALIGN.LEFT;
ctx.textBaseline = "top";
ctx.font = this._setupFont(s._font, s._size, s._bold, s._italic);
ctx.textAlign = s.isPureText ? (s._textAlign || exports.TEXT_ALIGN.LEFT) : exports.TEXT_ALIGN.LEFT;
ctx.textBaseline = s.isPureText ? 'top' : 'bottom';
if (typeof (s._fillColor) == "number")
s._fillColor = hex2string(s._fillColor);
ctx.fillStyle = s._textAlpha === 1 ? s._fillColor : getRGBA(s._fillColor, s._textAlpha);
......@@ -14969,18 +15142,30 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true,
configurable: true
});
TextField.prototype._getMeasuredWidth = function (text) {
TextField.prototype._getMeasuredWidth = function (text, style) {
var ctx = this.context;
ctx.save();
if (style && style.font) {
ctx.font = style.font;
}
var w = ctx.measureText(text).width;
ctx.restore();
return w;
};
TextField.prototype._getFontSize = function (style) {
if (style && style.font) {
return parseInt(style.font);
}
};
TextField.prototype.updateText = function () {
var s = this;
var text = s.pureText;
if (!text) {
s.canvas.width = 0;
s.canvas.height = 0;
s._localBoundsSelf.clear();
if (!this._width && !this._height) {
s._localBoundsSelf.clear();
}
this.anchorTexture = { x: 0, y: 0 };
this.updateTexture();
return;
......@@ -14989,15 +15174,18 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (!s.dirty)
return;
s.dirty = false;
var isPureText = s.isPureText;
text += "";
var can = s.canvas;
var ctx = s.context;
var hardLines = text.toString().split(/(?:\r\n|\r|\n)/);
var realLines = [];
var lineWidths = [];
var lineHeights = [];
s.realLines = realLines;
s._prepContext(ctx);
var textWidth = s._width;
if (text.indexOf("\n") < 0 && s.lineType == exports.TEXT_lINETYPE.SINGLE) {
if (isPureText && text.indexOf("\n") < 0 && s.lineType == exports.TEXT_lINETYPE.SINGLE) {
realLines[realLines.length] = hardLines[0];
var str = hardLines[0];
var lineW = s._getMeasuredWidth(str);
......@@ -15022,6 +15210,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
else {
var shouldMeasureTextWidth = !textWidth;
var index_1 = 0;
for (var i = 0, l = hardLines.length; i < l; i++) {
var str = hardLines[i];
if (!str)
......@@ -15029,49 +15218,71 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var lineWidth = 0;
for (var _i = 0, str_1 = str; _i < str_1.length; _i++) {
var char = str_1[_i];
var charWidth = measureChar(char);
var charWidth = measureChar(char, index_1);
lineWidth += charWidth;
index_1++;
}
if (shouldMeasureTextWidth) {
textWidth = Math.max(lineWidth, textWidth);
}
}
index_1 = 0;
for (var i = 0, l = hardLines.length; i < l; i++) {
var str = hardLines[i];
if (!str)
continue;
var w = measureCache[str[0]];
var w = measureChar(str[0], index_1++);
var lineStr = str[0];
var wordW = 0;
var strLen = str.length;
var lineHeight = 0;
for (var j = 1; j < strLen; j++) {
wordW = measureCache[str[j]];
wordW = measureChar(str[j], index_1);
w += wordW;
if (w > textWidth) {
realLines[realLines.length] = lineStr;
lineWidths.push(w - wordW);
lineHeights.push(lineHeight || s.size);
lineStr = str[j];
w = wordW;
lineHeight = 0;
}
else {
lineStr += str[j];
}
var style = this.getStyle(index_1);
var size = this._getFontSize(style);
if (size) {
if (size > lineHeight) {
lineHeight = size;
}
}
index_1++;
}
realLines[realLines.length] = lineStr;
lineWidths.push(w);
lineHeights.push(lineHeight || s.size);
}
}
var trueHeight = s.size * realLines.length + s._lineSpacing * (realLines.length - 1);
var maxH = s._height || trueHeight;
var maxW = textWidth;
var tx = 0;
if (s._textAlign == exports.TEXT_ALIGN.CENTER) {
tx = maxW * 0.5;
var maxH, trueHeight;
if (isPureText) {
trueHeight = s.size * realLines.length + s._lineSpacing * (realLines.length - 1);
}
else if (s._textAlign == exports.TEXT_ALIGN.RIGHT) {
tx = maxW;
else {
trueHeight = lineHeights.reduce(function (a, b) {
return a + b;
}, 0) + s._lineSpacing * (realLines.length - 1);
}
if (s._height) {
maxH = s._height;
}
else {
maxH = trueHeight;
}
var maxW = textWidth;
can.width = maxW + padding$1 * 2;
can.height = maxH + padding$1 * 2;
ctx.clearRect(0, 0, can.width, can.width);
ctx.clearRect(0, 0, can.width, can.height);
if (s.border) {
ctx.beginPath();
ctx.strokeStyle = "#000";
......@@ -15079,7 +15290,22 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
ctx.strokeRect(padding$1 + 0.5, padding$1 + 0.5, maxW, maxH);
ctx.closePath();
}
var tx = 0;
if (isPureText) {
if (s._textAlign == exports.TEXT_ALIGN.CENTER) {
tx = maxW * 0.5;
}
else if (s._textAlign == exports.TEXT_ALIGN.RIGHT) {
tx = maxW;
}
}
ctx.setTransform(1, 0, 0, 1, tx + padding$1, padding$1);
if (this._shadowBlur > 0) {
ctx.shadowBlur = this._shadowBlur;
ctx.shadowColor = this._shadowColor;
ctx.shadowOffsetX = this._shadowOffset.x;
ctx.shadowOffsetY = this._shadowOffset.y;
}
s._prepContext(ctx);
var lineH = s._lineSpacing + s.size;
var upY = 0;
......@@ -15092,9 +15318,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
var index = 0;
var lineY = upY;
for (var i = 0; i < realLines.length; i++) {
var line = realLines[i];
if (s.isPureText) {
if (isPureText) {
var y = upY + i * lineH;
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
......@@ -15104,38 +15331,37 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
ctx.fillText(line, 0, y, maxW);
}
else {
var lineWidth = 0;
for (var _a = 0, line_1 = line; _a < line_1.length; _a++) {
var char = line_1[_a];
var charWidth = measureChar(char);
lineWidth += charWidth;
var lineWidth = lineWidths[i];
var lineHeight = lineHeights[i];
lineY += s._lineSpacing + lineHeight;
var x = 0;
if (s._textAlign == exports.TEXT_ALIGN.CENTER) {
x = (maxW - lineWidth) * 0.5;
}
else if (s._textAlign == exports.TEXT_ALIGN.RIGHT) {
x = maxW - lineWidth;
}
var x = -lineWidth / 2;
for (var j = 0, lj = line.length; j < lj; j++) {
var char = line[j];
var style = s.getStyle(index);
if (style) {
if (style.hasOwnProperty('color')) {
ctx.fillStyle = style.color;
}
if (style.hasOwnProperty('stroke')) {
ctx.lineWidth = style.stroke * 2;
}
if (style.hasOwnProperty('strokeColor')) {
ctx.strokeStyle = style.strokeColor;
ctx.save();
for (var field in styleFields) {
if (style.hasOwnProperty(field)) {
ctx[styleFields[field]] = style[field];
}
}
}
else {
ctx.fillStyle = s.fillColor;
ctx.lineWidth = s.stroke;
if (s.stroke) {
ctx.strokeStyle = s.strokeColor;
ctx.lineWidth = s.stroke * 2;
ctx.strokeText(char, x, lineY);
}
var y = upY + i * lineH;
if (ctx.lineWidth > 0) {
ctx.strokeText(char, x, y);
ctx.fillText(char, x, lineY);
if (style) {
ctx.restore();
}
ctx.fillText(char, x, y);
x += measureChar(char);
x += measureChar(char, index);
index++;
}
}
......@@ -15146,10 +15372,18 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
s._localBoundsSelf.width = maxW;
s._localBoundsSelf.height = maxH;
s.updateTexture();
function measureChar(char) {
var w = measureCache[char];
function measureChar(char, index) {
var key = char + ':';
var style;
if (!isPureText && index !== undefined) {
style = s.getStyle(index);
if (style && style.font) {
key += style.font;
}
}
var w = measureCache[key];
if (w === undefined) {
w = measureCache[char] = s._getMeasuredWidth(char);
w = measureCache[char] = s._getMeasuredWidth(char, style);
}
return w;
}
......@@ -15604,7 +15838,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
configurable: true
});
ScrollViewBase.prototype.calMaxDistance = function () {
return this.viewPort[this.paramSize];
return this.viewPort[this.paramSize] + this.viewPort.getLocalBounds()[this.paramXY];
};
Object.defineProperty(ScrollViewBase.prototype, "direction", {
get: function () {
......@@ -16537,58 +16771,404 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return Node;
}(Container));
function playViewEffect(name, params, mutex, lastView, view, container, callback) {
var effect = name ? effects[name] : effects.simple;
effect = effect || effects.simple;
effect(params || {}, mutex, lastView, view, container, callback);
}
var effects = {
simple: function (params, mutex, lastView, view, container, callback) {
if (mutex) {
container.removeChild(lastView);
}
else {
if (lastView && !view) {
container.removeChild(lastView);
}
}
if (view) {
if (!view.parent) {
container.addChild(view);
}
view.visible = true;
}
callback();
},
fade: function (params, mutex, lastView, view, container, callback) {
var _a = params.duration, duration = _a === void 0 ? 300 : _a;
if (mutex) {
fadeOut(function () {
fadeIn(callback);
});
}
else {
fadeIn(callback);
}
function fadeOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to({ alpha: 0 }, duration)
.call(function () {
container.removeChild(lastView);
lastView.alpha = 1;
callback();
});
}
else {
callback();
}
}
function fadeIn(callback) {
if (view) {
view.visible = true;
view.alpha = 0;
Tween.get(view, null, null, true)
.to({ alpha: 1 }, params.duration || 300)
.call(function () {
callback();
});
}
else {
callback();
}
}
},
flew: function (params, mutex, lastView, view, container, callback) {
var _a = params.duration, duration = _a === void 0 ? 300 : _a, _b = params.direction, direction = _b === void 0 ? 'top' : _b, _c = params.ease, ease = _c === void 0 ? 'backOut' : _c;
var _d = exports.gameStage.stage, width = _d.width, height = _d.height;
var outPos = {};
switch (direction) {
case 'left':
outPos.x = -width;
break;
case 'right':
outPos.x = width;
break;
case 'top':
outPos.y = -height;
break;
case 'bottom':
outPos.y = height;
break;
}
var inEase = ease;
var outEase = ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out');
if (mutex) {
flewOut(function () {
flewIn(callback);
});
}
else {
if (lastView && !view) {
flewOut(callback);
}
else {
flewIn(callback);
}
}
function flewOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to(outPos, duration, Ease[outEase])
.call(function () {
container.removeChild(lastView);
injectProp(lastView, outPos);
callback();
});
}
else {
callback();
}
}
function flewIn(callback) {
if (view) {
var inPos = {
x: view.x,
y: view.y,
};
view.visible = true;
injectProp(view, outPos);
Tween.get(view, null, null, true)
.to(inPos, duration, Ease[inEase])
.call(function () {
callback();
});
}
else {
callback();
}
}
},
hulu: function (params, mutex, lastView, view, container, callback) {
var _a = params.duration, duration = _a === void 0 ? 300 : _a, _b = params.ease, ease = _b === void 0 ? 'backOut' : _b, _c = params.x, x = _c === void 0 ? 0 : _c, _d = params.y, y = _d === void 0 ? 0 : _d;
var inEase = ease;
var outEase = ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out');
var outPos = {
x: parseInt(x),
y: parseInt(y),
scaleX: 0, scaleY: 0,
};
if (mutex) {
huluOut(function () {
huluIn(callback);
});
}
else {
if (lastView && !view) {
huluOut(callback);
}
else {
huluIn(callback);
}
}
function huluOut(callback) {
if (lastView) {
outPos.x -= lastView.width / 2;
outPos.y -= lastView.height / 2;
Tween.get(lastView, null, null, true)
.to(outPos, duration, Ease[outEase])
.call(function () {
container.removeChild(lastView);
injectProp(lastView, { scaleX: 1, scaleY: 1 });
callback();
});
}
else {
callback();
}
}
function huluIn(callback) {
if (view) {
var inPos = {
x: view.x,
y: view.y,
scaleX: 1, scaleY: 1
};
outPos.x -= view.width / 2;
outPos.y -= view.height / 2;
view.visible = true;
injectProp(view, outPos);
Tween.get(view, null, null, true)
.to(inPos, duration, Ease[inEase])
.call(function () {
view.anchorX = 0;
view.anchorY = 0;
callback();
});
}
else {
callback();
}
}
},
zoom: function (params, mutex, lastView, view, container, callback) {
var _a = params.duration, duration = _a === void 0 ? 300 : _a, _b = params.ease, ease = _b === void 0 ? 'backOut' : _b;
var inEase = ease;
var outEase = ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out');
if (mutex) {
zoomOut(function () {
zoomIn(callback);
});
}
else {
if (lastView && !view) {
zoomOut(callback);
}
else {
zoomIn(callback);
}
}
function zoomOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to({ scaleX: 0, scaleY: 0 }, duration, Ease[outEase])
.call(function () {
container.removeChild(lastView);
injectProp(view, { scaleX: 1, scaleY: 1 });
callback();
});
}
else {
callback();
}
}
function zoomIn(callback) {
if (view) {
view.anchorX = view.width / 2;
view.anchorY = view.height / 2;
view.visible = true;
injectProp(view, { scaleX: 0, scaleY: 0 });
Tween.get(view, null, null, true)
.to({ scaleX: 1, scaleY: 1 }, duration, Ease[inEase])
.call(function () {
view.anchorX = 0;
view.anchorY = 0;
callback();
});
}
else {
callback();
}
}
},
};
var StackContainer = (function (_super) {
tslib_1.__extends(StackContainer, _super);
function StackContainer(mutex) {
function StackContainer(mutex, inserted) {
if (mutex === void 0) { mutex = true; }
if (inserted === void 0) { inserted = 0; }
var _this = _super.call(this) || this;
_this._stack = [];
_this._inserted = 0;
_this._playing = false;
_this._actionQueue = [];
_this._playNextAction = function () {
if (_this._playing || _this._actionQueue.length === 0) {
return;
}
var actionItem = _this._actionQueue.shift();
var args = [];
for (var i = 0, li = actionItem.args.length; i < li; i++) {
var argument = actionItem.args[i];
args.push(argument);
}
_this._playing = true;
_this['_' + actionItem.action].apply(_this, args)
.then(function () {
_this._playing = false;
setTimeout(_this._playNextAction, 1);
});
};
_this._mutex = mutex;
_this._inserted = inserted;
_this.percentWidth = 100;
_this.percentHeight = 100;
_this.mouseEnabled = false;
_this.addEventListener(Event.START, function () {
_this.mouseChildren = false;
});
_this.addEventListener(Event.COMPLETE, function () {
_this.mouseChildren = true;
});
return _this;
}
StackContainer.prototype.push = function (view, options, dispatch) {
if (dispatch === void 0) { dispatch = true; }
if (this._mutex && this.children.length > 0) {
this._stack.push(this.removeChildAt(0));
}
this.addChild(view);
if (dispatch) {
this.dispatchEvent('change', { action: 'push', view: view, options: options });
}
Object.defineProperty(StackContainer.prototype, "childNum", {
get: function () {
var len = this.children.length;
return len > 0 ? len - this._inserted : 0;
},
enumerable: true,
configurable: true
});
StackContainer.prototype.push = function (view, options, playEffect) {
if (playEffect === void 0) { playEffect = true; }
this._actionQueue.push({ action: 'push', args: arguments });
this._playNextAction();
};
StackContainer.prototype.pop = function (options, playEffect) {
if (playEffect === void 0) { playEffect = true; }
this._actionQueue.push({ action: 'pop', args: arguments });
this._playNextAction();
};
StackContainer.prototype.replace = function (view, options, playEffect) {
if (playEffect === void 0) { playEffect = true; }
this._actionQueue.push({ action: 'replace', args: arguments });
this._playNextAction();
};
StackContainer.prototype.popAll = function (view, options, playEffect) {
if (playEffect === void 0) { playEffect = true; }
this._actionQueue.push({ action: 'popAll', args: arguments });
this._playNextAction();
};
StackContainer.prototype._push = function (view, options, playEffect) {
var _this = this;
if (playEffect === void 0) { playEffect = true; }
return new Promise(function (resolve) {
var action = 'push';
var lastView;
if (_this._mutex && _this.childNum > 0) {
lastView = _this.getChildAt(0);
_this._stack.push(lastView);
}
view.visible = false;
_this.addChild(view);
var data = { action: action, view: view, lastView: lastView, options: options, hasView: true };
_this.dispatchEvent(Event.START, data);
playViewEffect(playEffect ? options ? options.effect : null : null, options ? options.effectParams : {}, _this._mutex, lastView, view, _this, function () {
_this.dispatchEvent(Event.COMPLETE, data);
resolve();
});
});
};
StackContainer.prototype.replace = function (view, options) {
if (this.pop(false)) {
this.push(view, options, false);
this.dispatchEvent('change', { action: 'replace', view: view, options: options });
}
StackContainer.prototype._pop = function (options, playEffect) {
var _this = this;
if (playEffect === void 0) { playEffect = true; }
return new Promise(function (resolve) {
var action = 'pop';
var len = _this.childNum;
if (len <= 0) {
return false;
}
var lastView = _this.getChildAt(_this.children.length - 1);
var view;
if (_this._mutex) {
view = _this._stack.pop();
view.visible = false;
_this.addChild(view);
}
var data = { action: action, view: view, lastView: lastView, options: options, hasView: len > 1 };
_this.dispatchEvent(Event.START, data);
playViewEffect(playEffect ? options ? options.effect : null : null, options ? options.effectParams : {}, _this._mutex, lastView, view, _this, function () {
_this.dispatchEvent(Event.COMPLETE, data);
resolve();
});
});
};
StackContainer.prototype.pop = function (dispatch) {
if (dispatch === void 0) { dispatch = true; }
var len = this.children.length;
if (len <= 1) {
return false;
}
this.removeChildAt(len - 1);
if (this._mutex) {
this.addChild(this._stack.pop());
}
if (dispatch) {
this.dispatchEvent('change', { action: 'pop' });
}
return true;
StackContainer.prototype._replace = function (view, options, playEffect) {
var _this = this;
if (playEffect === void 0) { playEffect = true; }
return new Promise(function (resolve) {
var action = 'replace';
var len = _this.childNum;
if (len <= 0) {
return false;
}
var lastView = _this.getChildAt(len - 1);
view.visible = false;
_this.addChild(view);
var data = { action: action, view: view, lastView: lastView, options: options, hasView: len > 1 };
_this.dispatchEvent(Event.START, data);
playViewEffect(playEffect ? options ? options.effect : null : null, options ? options.effectParams : {}, _this._mutex, lastView, view, _this, function () {
_this.dispatchEvent(Event.COMPLETE, data);
resolve();
});
});
};
StackContainer.prototype.popAll = function (view, options) {
this.removeChildren();
if (this._mutex) {
this._stack.splice(0);
}
if (view) {
this.push(view, options, false);
}
this.dispatchEvent('change', { action: 'popAll', view: view, options: options });
StackContainer.prototype._popAll = function (view, options, playEffect) {
var _this = this;
if (playEffect === void 0) { playEffect = true; }
return new Promise(function (resolve) {
var action = 'popAll';
var lastView = _this.getChildAt(0);
var len = _this.childNum;
while (_this.children.length > 1) {
_this.removeChildAt(1);
}
if (_this._mutex) {
_this._stack.splice(0);
}
if (view) {
view.visible = false;
_this.addChild(view);
}
var data = { action: action, view: view, lastView: lastView, options: options, hasView: len > 1 };
_this.dispatchEvent(Event.START, data);
playViewEffect(playEffect ? options ? options.effect : null : null, options ? options.effectParams : {}, _this._mutex, lastView, view, _this, function () {
_this.dispatchEvent(Event.COMPLETE, data);
resolve();
});
});
};
return StackContainer;
}(Node$1));
......@@ -18761,6 +19341,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
Rect.prototype.redraw = function () {
var _a = this, width = _a.width, height = _a.height, borderRadius = _a.borderRadius;
if (width == 0 || height == 0) {
return;
}
if (borderRadius > 0) {
this.drawRoundedRect(0, 0, width, height, borderRadius);
}
......@@ -18781,6 +19364,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Circle.prototype.redraw = function () {
_super.prototype.redraw.call(this);
var _a = this, width = _a.width, height = _a.height;
if (width == 0 || height == 0) {
return;
}
var radius = Math.min(width, height) / 2;
this.drawCircle(radius, radius, radius);
};
......@@ -18793,6 +19379,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
function Image() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.isUI = true;
_this.crossOrigin = true;
_this._escapes = [];
_this._registeredEvents = [];
return _this;
......@@ -18823,7 +19410,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
url = assetConfig.uuid;
}
}
this.texture = Texture.fromImage(url);
this.texture = Texture.fromImage(url, this.crossOrigin);
}
else {
this.texture = null;
......@@ -19141,7 +19728,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
TextInput.prototype.onClickStatic = function () {
this.setFocus();
this.stage.once(MouseEvent.CLICK, this.onClickStage, this);
this.stage.once(MouseEvent.MOUSE_DOWN, this.onClickStage, this);
};
TextInput.prototype.onResize = function () {
var pl = this._placeholderLabel;
......@@ -19362,6 +19949,27 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
HtmlView.prototype.afterConstructor = function () {
};
Object.defineProperty(HtmlView.prototype, "$store", {
get: function () {
var p = this;
do {
if (p['$isViewRoot']) {
break;
}
p = p.parent;
} while (p.parent);
if (p) {
return p['$_store'];
}
},
enumerable: true,
configurable: true
});
HtmlView.prototype.findChildByUUID = function (uuid) {
if (this['uuid'] === uuid) {
return this;
}
};
HtmlView = tslib_1.__decorate([
afterConstructor,
applyAutoAdjust,
......@@ -19440,29 +20048,41 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
Toast.prototype.show = function (props) {
if (props === void 0) { props = {}; }
if (!props.text) {
return;
}
var contentView = this.getContent(props.viewName);
var lab = contentView.getChildByName('lab');
if (!lab) {
console.warn('[lab] child no exists on toast view');
return;
}
var text = props.text, _a = props.padding, padding = _a === void 0 ? 10 : _a, _b = props.duration, duration = _b === void 0 ? 1000 : _b, _c = props.showDuration, showDuration = _c === void 0 ? 300 : _c, _d = props.hideDuration, hideDuration = _d === void 0 ? 200 : _d;
lab.text = text;
lab.x = lab.y = padding;
this.width = contentView.width = lab.width + padding * 2;
this.height = contentView.height = lab.height + padding * 2;
if (!contentView.visible) {
contentView.visible = true;
contentView.alpha = 0;
}
Tween.get(contentView, null, null, true)
.to({ alpha: 1 }, showDuration)
.wait(duration)
.to({ alpha: 0 }, hideDuration)
.call(this.removeContentView, this);
return tslib_1.__awaiter(this, void 0, void 0, function () {
var contentView, lab, text, _a, padding, paddingH, paddingV, _b, duration, _c, showDuration, _d, hideDuration;
return tslib_1.__generator(this, function (_e) {
switch (_e.label) {
case 0:
if (!props.text) {
return [2];
}
return [4, this.getContent(props.viewName, props)];
case 1:
contentView = _e.sent();
lab = contentView.getChildByName('lab');
if (!lab) {
console.warn('[lab] child no exists on toast view');
return [2];
}
text = props.text, _a = props.padding, padding = _a === void 0 ? 10 : _a, paddingH = props.paddingH, paddingV = props.paddingV, _b = props.duration, duration = _b === void 0 ? 1000 : _b, _c = props.showDuration, showDuration = _c === void 0 ? 300 : _c, _d = props.hideDuration, hideDuration = _d === void 0 ? 200 : _d;
lab.text = text;
lab.x = paddingH || padding;
lab.y = paddingV || padding;
this.width = contentView.width = lab.width + (paddingH || padding) * 2;
this.height = contentView.height = lab.height + (paddingV || padding) * 2;
if (!contentView.visible) {
contentView.visible = true;
contentView.alpha = 0;
}
Tween.get(contentView, null, null, true)
.to({ alpha: 1 }, showDuration)
.wait(duration)
.to({ alpha: 0 }, hideDuration)
.call(this.removeContentView, this);
return [2];
}
});
});
};
Toast.prototype.hide = function (animation, hideDuration) {
if (animation === void 0) { animation = true; }
......@@ -19485,37 +20105,48 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this.removeChild(this._content);
this._content = null;
};
Toast.prototype.getContent = function (viewName) {
var view;
if (this.children.length == 0) {
if (viewName) {
view = this._gameStage.instantiateView(viewName);
}
if (!view) {
if (!this._contentSample) {
this._contentSample = new Node$1();
var bg = new Rect();
bg.borderRadius = 10;
bg.percentWidth = 100;
bg.percentHeight = 100;
bg.fillColor = 'black';
bg.alpha = 0.7;
this._contentSample.addChild(bg);
var lab = new Label();
lab.name = 'lab';
lab.fillColor = 'white';
lab.size = 30;
this._contentSample.addChild(lab);
Toast.prototype.getContent = function (viewName, props) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var view, _a, borderRadius, _b, labColor, _c, labSize, _d, bgColor, _e, bgAlpha, bg, lab;
return tslib_1.__generator(this, function (_f) {
switch (_f.label) {
case 0:
if (!(this.children.length == 0)) return [3, 3];
if (!viewName) return [3, 2];
return [4, this._gameStage.instantiateView(viewName)];
case 1:
view = _f.sent();
_f.label = 2;
case 2:
if (!view) {
if (!this._contentSample) {
_a = props.borderRadius, borderRadius = _a === void 0 ? 10 : _a, _b = props.labColor, labColor = _b === void 0 ? 'white' : _b, _c = props.labSize, labSize = _c === void 0 ? 30 : _c, _d = props.bgColor, bgColor = _d === void 0 ? 'black' : _d, _e = props.bgAlpha, bgAlpha = _e === void 0 ? 0.7 : _e;
this._contentSample = new Node$1();
bg = new Rect();
bg.borderRadius = borderRadius;
bg.percentWidth = 100;
bg.percentHeight = 100;
bg.fillColor = bgColor;
bg.alpha = bgAlpha;
this._contentSample.addChild(bg);
lab = new Label();
lab.name = 'lab';
lab.fillColor = labColor;
lab.size = labSize;
this._contentSample.addChild(lab);
}
view = this._contentSample;
}
this._content = view;
this.addChild(view);
return [3, 4];
case 3:
view = this.getChildAt(0);
_f.label = 4;
case 4: return [2, view];
}
view = this._contentSample;
}
this._content = view;
this.addChild(view);
}
else {
view = this.getChildAt(0);
}
return view;
});
});
};
return Toast;
}(Node$1));
......@@ -20183,11 +20814,133 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return customMap[id].props || {};
}
function dealPxEnv() {
if (queryParams.appID) {
env.appID = queryParams.appID;
}
if (queryParams.channelType) {
env.channelType = queryParams.channelType;
}
if (queryParams.projectID) {
env.projectID = queryParams.projectID;
}
else {
var result = window.location.pathname.match(/\/projectx\/(.*?)\/.*?/);
if (result) {
env.projectID = result[1];
}
}
if (queryParams.is_from_share) {
env.fromShare = true;
}
var newUser = true;
var key = 'nu_' + env.appID + '_' + env.projectID;
var v = localStorage.getItem(key);
if (v) {
newUser = false;
}
else {
localStorage.setItem(key, '1');
}
env.newUser = newUser;
if (window['isSharePage']) {
accessLog(506);
}
}
function cleanNewUser() {
var key = 'nu_' + env.appID + '_' + env.projectID;
localStorage.removeItem(key);
}
function dealPageRemainTime() {
var startTimer = new Date().getTime();
var endTimer;
var visibilityChange;
if (typeof document.hidden !== 'undefined') {
visibilityChange = 'visibilitychange';
}
else if (typeof document['msHidden'] !== 'undefined') {
visibilityChange = 'msvisibilitychange';
}
else if (typeof document['webkitHidden'] !== 'undefined') {
visibilityChange = 'webkitvisibilitychange';
}
var handleVisibilityChange = function (e) {
if (document.visibilityState == "visible") {
startTimer = new Date().getTime();
}
if (document.visibilityState == "hidden") {
endTimer = new Date().getTime();
sendData();
}
};
var sendData = function () {
var t0 = endTimer - startTimer;
accessLog(156, {
remain: t0,
});
};
document.addEventListener(visibilityChange, handleVisibilityChange, false);
document.body['onbeforeunload'] = function () {
endTimer = new Date().getTime();
return sendData();
};
}
function accessLog(pagebizid, params) {
var p = {
pagebizid: pagebizid,
};
injectProp(p, params);
return httpRequest('buriedPoint', 'get', p);
}
var GameStage = (function (_super) {
tslib_1.__extends(GameStage, _super);
function GameStage(stage) {
var _this = _super.call(this) || this;
_this._viewCache = {};
_this.lazyLoadAllAssets = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, assets, customs, _b, _c, _i, uuid, group, _d, customs_1, custom, group;
return tslib_1.__generator(this, function (_e) {
switch (_e.label) {
case 0:
_a = this._config, assets = _a.assets, customs = _a.customs;
if (!!Array.isArray(assets)) return [3, 4];
_b = [];
for (_c in assets)
_b.push(_c);
_i = 0;
_e.label = 1;
case 1:
if (!(_i < _b.length)) return [3, 4];
uuid = _b[_i];
group = assets[uuid];
if (!(group && group.length > 0)) return [3, 3];
return [4, loadAssetsGroup(group, uuid)];
case 2:
_e.sent();
_e.label = 3;
case 3:
_i++;
return [3, 1];
case 4:
_d = 0, customs_1 = customs;
_e.label = 5;
case 5:
if (!(_d < customs_1.length)) return [3, 8];
custom = customs_1[_d];
group = custom.assets;
if (!(group && group.length > 0)) return [3, 7];
return [4, loadAssetsGroup(group, custom.id)];
case 6:
_e.sent();
_e.label = 7;
case 7:
_d++;
return [3, 5];
case 8: return [2];
}
});
}); };
_this.name = 'game-stage';
stage.width = stage.viewRect.width;
stage.height = stage.viewRect.height;
......@@ -20196,20 +20949,24 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
_this.percentWidth = 100;
_this.percentHeight = 100;
_this.mouseEnabled = false;
var blackLayer = _this._blackLayer = new Rect();
var loadingView = _this._loadingView = new Container();
_this.addChild(_this._sceneContainer = new StackContainer());
_this.addChild(blackLayer);
_this.addChild(_this._popupContainer = new StackContainer());
_this.addChild(_this._popupContainer = new StackContainer(false, 1));
_this.addChild(_this._toast = new Toast(_this));
_this.addChild(loadingView);
var blackLayer = _this._blackLayer = new Rect();
blackLayer.name = 'blackLayer';
blackLayer.percentWidth = 100;
blackLayer.percentHeight = 100;
blackLayer.visible = false;
blackLayer.width = stage.width;
blackLayer.height = stage.height;
blackLayer.fillColor = 0;
blackLayer.alpha = 0.7;
loadingView.percentWidth = 100;
loadingView.percentHeight = 100;
loadingView.visible = false;
_this._sceneContainer.name = 'scene-container';
_this._popupContainer.name = 'popup-container';
_this._popupContainer.addEventListener('change', _this.onPopupContainerChange, _this);
_this._popupContainer.addEventListener(Event.START, _this.onPopupContainerStart, _this);
_this._popupContainer.addEventListener(Event.COMPLETE, _this.onPopupContainerComplete, _this);
return _this;
}
Object.defineProperty(GameStage.prototype, "sceneContainer", {
......@@ -20244,51 +21001,33 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return tslib_1.__awaiter(this, void 0, void 0, function () {
function p() {
loaded++;
onAssetsProgress && onAssetsProgress(loaded, total);
onPreloadAssetsProgress && onPreloadAssetsProgress(loaded, total);
if (loaded >= total) {
onAssetsComplete && onAssetsComplete();
onPreloadAssetsComplete && onPreloadAssetsComplete();
}
}
var assets, customs, loaded, total, _i, customs_1, custom, _a, customs_2, custom;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
var assets, customs, loaded, assetsToLoad, total;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
this._config = config;
assets = config.assets, customs = config.customs;
loaded = 0;
total = assets.length;
if (customs) {
for (_i = 0, customs_1 = customs; _i < customs_1.length; _i++) {
custom = customs_1[_i];
if (custom.assets) {
total += custom.assets.length;
}
}
assetsToLoad = assets;
if (!Array.isArray(assets)) {
assetsToLoad = assets['common'];
}
return [4, loadAssetGroup(assets, p).catch(function (e) {
total = assetsToLoad.length;
return [4, loadAssets(assetsToLoad, p).catch(function (e) {
console.log(e);
})];
case 1:
_b.sent();
if (!customs) return [3, 5];
_a = 0, customs_2 = customs;
_b.label = 2;
case 2:
if (!(_a < customs_2.length)) return [3, 5];
custom = customs_2[_a];
if (!custom.assets) return [3, 4];
return [4, loadAssetGroup(custom.assets, p).catch(function (e) {
console.log(e);
})];
case 3:
_b.sent();
_b.label = 4;
case 4:
_a++;
return [3, 2];
case 5:
_a.sent();
this.start();
dealPxEnv();
dealPageRemainTime();
onStart && onStart();
setTimeout(this.lazyLoadAllAssets, this._config.options.lazyLoadWait || 1000);
return [2];
}
});
......@@ -20304,62 +21043,168 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this.dataCenter.registerDataMapping(dataMapping);
}
setProcessMetaLibs(processes, builtinProcesses);
setTimeout(function () {
var sceneEntry = _this.instantiateView(entrySceneView);
if (sceneEntry) {
_this._sceneContainer.push(sceneEntry);
}
setTimeout(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var sceneEntry;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.instantiateView(entrySceneView)];
case 1:
sceneEntry = _a.sent();
if (sceneEntry) {
this._sceneContainer.push(sceneEntry);
}
return [2];
}
});
}); });
};
GameStage.prototype.showInnerLoadingView = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var loadingViewName, loadingView;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
loadingViewName = this._config.options.loadingView;
loadingView = this._loadingView.getChildAt(0);
if (!(this._loadingView.children.length == 0 && loadingViewName)) return [3, 2];
return [4, this.instantiateView(loadingViewName, true, false)];
case 1:
loadingView = _a.sent();
this._loadingView.addChild(loadingView);
_a.label = 2;
case 2:
this._loadingView.visible = true;
return [2];
}
});
});
};
GameStage.prototype.instantiateView = function (name, cache) {
GameStage.prototype.hideInnerLoadingView = function () {
if (this._loadingView.visible) {
this._loadingView.visible = false;
}
};
GameStage.prototype.instantiateView = function (name, cache, showLoadingView) {
if (cache === void 0) { cache = true; }
var view;
if (cache) {
view = this._viewCache[name];
}
if (!view) {
var viewConfig = this.getViewConfigByName(name);
if (viewConfig) {
view = instantiate(viewConfig);
var store = {};
if (viewConfig.store) {
var _a = viewConfig.store, exp = _a.exp, computed = _a.computed;
store = createStore(exp, computed);
}
view['$isViewRoot'] = true;
view['$_store'] = store;
console.time('bind');
bind(store, view);
console.timeEnd('bind');
if (cache) {
this._viewCache[name] = view;
if (showLoadingView === void 0) { showLoadingView = true; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var view, viewConfig, _a, assets, customs, groups, depCustoms, _i, customs_2, custom, depAssets, store, _b, exp, computed;
var _this = this;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
if (cache) {
view = this._viewCache[name];
}
if (!!view) return [3, 4];
viewConfig = this.getViewConfigByName(name);
if (!viewConfig) return [3, 3];
_a = this._config, assets = _a.assets, customs = _a.customs;
if (!!Array.isArray(assets)) return [3, 2];
groups = {};
depCustoms = viewConfig.depCustoms;
if (depCustoms && depCustoms.length > 0) {
for (_i = 0, customs_2 = customs; _i < customs_2.length; _i++) {
custom = customs_2[_i];
if (depCustoms.indexOf(custom.id) >= 0 && custom.assets) {
if (!checkAssetGroupLoaded(custom.id)) {
groups[custom.id] = custom.assets;
}
}
}
}
if (!checkAssetGroupLoaded(viewConfig.uuid)) {
depAssets = assets[viewConfig.uuid];
if (depAssets && depAssets.length > 0) {
groups[viewConfig.uuid] = depAssets;
}
}
return [4, loadAssetsGroups(groups, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!showLoadingView) return [3, 2];
return [4, this.showInnerLoadingView()];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2];
}
});
}); }, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
if (showLoadingView) {
this.hideInnerLoadingView();
}
return [2];
});
}); })];
case 1:
_c.sent();
_c.label = 2;
case 2:
view = instantiate(viewConfig);
store = {};
if (viewConfig.store) {
_b = viewConfig.store, exp = _b.exp, computed = _b.computed;
store = createStore(exp, computed);
}
view['$isViewRoot'] = true;
view['$_store'] = store;
console.time('bind');
bind(store, view);
console.timeEnd('bind');
if (cache) {
this._viewCache[name] = view;
}
return [3, 4];
case 3:
console.error('view config not exists:', name);
_c.label = 4;
case 4: return [2, view];
}
}
else {
console.error('view config not exists:', name);
}
}
return view;
});
});
};
GameStage.prototype.getViewConfigByName = function (name) {
return arrayFind(this._config.views, function (view) { return view.name === name; });
};
GameStage.prototype.setBlackLayerVisible = function (visible) {
this._blackLayer.visible = visible;
};
GameStage.prototype.onPopupContainerChange = function (e) {
var _a = e.data, action = _a.action, view = _a.view, options = _a.options;
GameStage.prototype.onPopupContainerStart = function (e) {
var _a = e.data, action = _a.action, view = _a.view, lastView = _a.lastView, options = _a.options, hasView = _a.hasView;
var target = e.target;
switch (action) {
case 'push':
case 'replace':
case 'popAll':
if (options && options.center) {
view.horizonCenter = 0;
view.verticalCenter = 0;
view.x = (target.width - view.width) / 2;
view.y = (target.height - view.height) / 2;
}
break;
}
this.setBlackLayerVisible(this._popupContainer.children.length > 0);
var blackLayer = this._blackLayer;
var pParent = blackLayer.parent;
if (hasView) {
target.addChildAt(blackLayer, target.childNum - 1 - (view ? 0 : 1));
var modalAlpha = 0.7;
if (options && options.hasOwnProperty('modalAlpha')) {
modalAlpha = options.modalAlpha;
}
if (!pParent || blackLayer['tween_count'] > 0) {
blackLayer.alpha = 0;
Tween.get(blackLayer, null, null, true)
.to({ alpha: modalAlpha }, 300);
}
}
else if (pParent) {
Tween.get(blackLayer, null, null, true)
.to({ alpha: 0 }, 300)
.call(function () {
pParent.removeChild(blackLayer);
});
}
};
GameStage.prototype.onPopupContainerComplete = function (e) {
};
return GameStage;
}(Node$1));
......@@ -20483,8 +21328,8 @@ 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;
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 _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;
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 () {
......@@ -20670,11 +21515,15 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.URL_FILE_EXTENSION = URL_FILE_EXTENSION;
exports.VERSION = VERSION;
exports.abs = abs;
exports.accessLog = accessLog;
exports.addCustomModule = addCustomModule;
exports.appendScript = appendScript;
exports.applyEvents = applyEvents;
exports.applyScript = applyScript;
exports.arrayFind = arrayFind;
exports.backupCanvas = backupCanvas;
exports.checkAssetGroupLoaded = checkAssetGroupLoaded;
exports.cleanNewUser = cleanNewUser;
exports.clearTextureCache = clearTextureCache;
exports.cmdOldPrefix = cmdOldPrefix;
exports.cmdPrefix = cmdPrefix;
......@@ -20737,7 +21586,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.launchWithWindowVariable = launchWithWindowVariable;
exports.linkScheme = linkScheme;
exports.linkedFlag = linkedFlag;
exports.loadAssetGroup = loadAssetGroup;
exports.loadAssets = loadAssets;
exports.loadAssetsGroup = loadAssetsGroup;
exports.loadAssetsGroups = loadAssetsGroups;
exports.log10 = log10;
exports.log2 = log2;
exports.mapWebGLBlendModesToPixi = mapWebGLBlendModesToPixi;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{"id":"engine","url":"engine.d2f4eafa108b00ed5ac00e2d30ee98f8af4a9118.js"}
\ No newline at end of file
{"id":"engine","url":"engine.dee8bb73f7c234c7fe2527549add0fab7ca3d3fc.js"}
\ No newline at end of file
......@@ -439,41 +439,40 @@ export default class Container extends DisplayObject {
this._lastBoundsID = this._boundsID
this._bounds.clear();
//算自己的
this._calculateBounds();
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
if (!child.visible || !child.renderable) {
continue;
}
child.calculateBounds();
if (child.$mask) {
child.$mask.calculateBounds();
//取交集矩形
if (child._bounds.x < child.$mask._bounds.x) {
child._bounds.x = child.$mask._bounds.x;
}
if (child._bounds.y < child.$mask._bounds.y) {
child._bounds.y = child.$mask._bounds.y;
if(!this._calculateBounds()){
for (let i = 0; i < this.children.length; i++) {
const child = this.children[i];
if (!child.visible || !child.renderable) {
continue;
}
if (child._bounds.width > child.$mask._bounds.width) {
child._bounds.width = child.$mask._bounds.width;
}
if (child._bounds.height > child.$mask._bounds.height) {
child._bounds.height = child.$mask._bounds.height;
child.calculateBounds();
if (child.$mask) {
child.$mask.calculateBounds();
//取交集矩形
if (child._bounds.x < child.$mask._bounds.x) {
child._bounds.x = child.$mask._bounds.x;
}
if (child._bounds.y < child.$mask._bounds.y) {
child._bounds.y = child.$mask._bounds.y;
}
if (child._bounds.width > child.$mask._bounds.width) {
child._bounds.width = child.$mask._bounds.width;
}
if (child._bounds.height > child.$mask._bounds.height) {
child._bounds.height = child.$mask._bounds.height;
}
Rectangle.createFromRects(this._bounds, child._bounds);
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
}
Rectangle.createFromRects(this._bounds, child._bounds);
} else {
Rectangle.createFromRects(this._bounds, child._bounds);
}
}
}
/**
* 加"_"的方法基本是为了自己特殊处理
*/
protected _calculateBounds() {
protected _calculateBounds(): boolean {
//子类自己重写
//let wp = this.worldMatrix.transformPoint(this.x, this.y);
......@@ -496,7 +495,10 @@ export default class Container extends DisplayObject {
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
return true;
}
return false;
}
/**
......@@ -704,7 +706,8 @@ export default class Container extends DisplayObject {
* @member {number}
*/
get width(): number {
return this._width || this.scale.x * this.getLocalBounds().width;
let value = this._width;
return !value && value != 0 ? this.scale.x * this.getLocalBounds().width : value;
}
set width(value: number) {
......@@ -716,10 +719,14 @@ export default class Container extends DisplayObject {
// this.scale.x = 1;
// }
if (this._width !== value) {
//子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
if (!value && value != 0) {
this._width = undefined;
} else {
//子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
}
}
......@@ -729,7 +736,8 @@ export default class Container extends DisplayObject {
* @member {number}
*/
get height(): number {
return this._height || this.scale.y * this.getLocalBounds().height;
let value = this._height;
return !value && value != 0 ? this.scale.y * this.getLocalBounds().height : value;
}
set height(value: number) {
......@@ -740,10 +748,14 @@ export default class Container extends DisplayObject {
// } else {
// this.scale.y = 1;
// }
if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
if (!value && value != 0) {
this._height = undefined;
} else {
if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
}
}
......
......@@ -94,9 +94,9 @@ export default class Sprite extends Container {
this._texture = null;
this._width = 0;
//this._width = 0;
this._height = 0;
//this._height = 0;
this._tint = null;
this._tintRGB = null;
......@@ -391,14 +391,22 @@ export default class Sprite extends Container {
* @member {number}
*/
get width() {
return Math.abs(this.scale.x) * this._texture.orig.width;
let value = this._width;
return !value && value != 0 ? Math.abs(this.scale.x) * this._texture.orig.width : value;
}
set width(value) {
const s = sign(this.scale.x) || 1;
this.scale.x = s * value / this._texture.orig.width;
this._width = value;
if (this._width !== value) {
if (!value && value != 0) {
this.scale.x = 1;
this._width = undefined;
} else {
const s = sign(this.scale.y) || 1;
this.scale.x = s * value / this._texture.orig.width;
this._width = value;
}
this.dispatchEvent(Event.RESIZE);
}
}
/**
......@@ -406,13 +414,22 @@ export default class Sprite extends Container {
* @member {number}
*/
get height() {
return Math.abs(this.scale.y) * this._texture.orig.height;
let value = this._height;
return !value && value != 0 ? Math.abs(this.scale.y) * this._texture.orig.height : value;
}
set height(value) {
const s = sign(this.scale.y) || 1;
this.scale.y = s * value / this._texture.orig.height;
this._height = value;
if (this._height !== value) {
if (!value && value != 0) {
this.scale.y = 1;
this._height = undefined;
} else {
const s = sign(this.scale.y) || 1;
this.scale.y = s * value / this._texture.orig.height;
this._height = value;
}
this.dispatchEvent(Event.RESIZE);
}
}
/**
......
......@@ -559,7 +559,7 @@ export class Stage extends Container {
* @return {{w: number, h: number}}
*/
public getRootDivWH(div: HTMLDivElement) {
let sw = div.style.width;
/*let sw = div.style.width;
let sh = div.style.height;
let iw = document.body.clientWidth;
// let ih = document.body.clientHeight-40;
......@@ -580,7 +580,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};
}
/**
......
......@@ -169,28 +169,42 @@ export class TextField extends Sprite {
// private _textHeight: number = 0;
get width(): number {
if (this._width) return this._width;
this.updateText();
return this.scale.x * this.getLocalBounds().width;
if (!this._width && this._width != 0) {
this.updateText();
return this.scale.x * this.getLocalBounds().width;
} else {
return this._width;
}
}
set width(value: number) {
if (this._width !== value) {
this._width = value;
if (!value && value != 0) {
this._width = undefined;
} else {
this._width = value;
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
}
}
get height(): number {
if (this._height) return this._height;
this.updateText();
return this.scale.y * this.getLocalBounds().height;
if (!this._height && this._height != 0) {
this.updateText();
return this.scale.y * this.getLocalBounds().height;
} else {
return this._height;
}
}
set height(value: number) {
if (this._height !== value) {
this._height = value;
if (!value && value != 0) {
this._height = undefined;
} else {
this._height = value;
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
}
......@@ -691,7 +705,7 @@ export class TextField extends Sprite {
s.realLines = realLines;
s._prepContext(ctx);
let textWidth = s._width;
let textWidth = !s._width && s._width != 0 ? 0 : s._width;
// let lineH = s._lineSpacing + s.size;
//单行文本时
if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
......@@ -719,7 +733,7 @@ export class TextField extends Sprite {
}
} else {
//textWidth取每行最大值,如果没设置过textWidth
const shouldMeasureTextWidth = !textWidth;
const shouldMeasureTextWidth = !s._width && s._width != 0 ? true : false;
let index = 0;
for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i];
......@@ -906,6 +920,19 @@ export class TextField extends Sprite {
}
}
/**
* 更新自己的bounds,计算全局
* @private
*/
_calculateBounds() {
const {width, height} = this._localBoundsSelf;
var matrix = this.transform.worldMatrix;
this._bounds.x = matrix.tx;
this._bounds.y = matrix.ty;
this._bounds.width = width;
this._bounds.height = height;
}
/**
* 更新texture及baseTexture属性
* 不考虑trim,
......
......@@ -4,7 +4,7 @@
import {Stage} from "../../2d/display/index";
import {StackContainer} from "./StackContainer";
import {loadAssets} from "./assets-manager";
import {checkAssetGroupLoaded, loadAssetsGroup, loadAssets, loadAssetsGroups} from "./assets-manager";
import {instantiate} from "./view-interpreter";
import {dataCenter, DataCenter} from "./data-center";
import {setProcessMetaLibs} from "../behavior-runtime/index";
......@@ -17,6 +17,8 @@ import {Node} from "./nodes/Node";
import {bind, createStore} from "./mvvm/index";
import {registerCustomModules} from "./custom-module";
import {dealPageRemainTime, dealPxEnv} from "../px-logics";
import Container from "../../2d/display/Container";
import {Event} from "../../2d/events/Event";
/**
* 游戏舞台
......@@ -24,6 +26,7 @@ import {dealPageRemainTime, dealPxEnv} from "../px-logics";
export class GameStage extends Node {
private _sceneContainer: StackContainer; //场景容器
private _popupContainer: StackContainer; //弹层容器
private _loadingView: Container;
private _toast: Toast;
private _blackLayer: Rect;
private _stage;
......@@ -46,25 +49,29 @@ export class GameStage extends Node {
this.percentHeight = 100;
this.mouseEnabled = false;
let blackLayer = this._blackLayer = new Rect();
let loadingView = this._loadingView = new Container();
this.addChild(this._sceneContainer = new StackContainer());
this.addChild(blackLayer);
this.addChild(this._popupContainer = new StackContainer());
this.addChild(this._popupContainer = new StackContainer(false, 1));
this.addChild(this._toast = new Toast(this));
this.addChild(loadingView);
let blackLayer = this._blackLayer = new Rect();
blackLayer.name = 'blackLayer';
blackLayer.percentWidth = 100;
blackLayer.percentHeight = 100;
blackLayer.visible = false;
blackLayer.width = stage.width;
blackLayer.height = stage.height;
blackLayer.fillColor = 0;
blackLayer.alpha = 0.7;
loadingView.percentWidth = 100;
loadingView.percentHeight = 100;
loadingView.visible = false;
this._sceneContainer.name = 'scene-container';
this._popupContainer.name = 'popup-container';
this._popupContainer.addEventListener('change', this.onPopupContainerChange, this);
this._popupContainer.addEventListener(Event.START, this.onPopupContainerStart, this);
this._popupContainer.addEventListener(Event.COMPLETE, this.onPopupContainerComplete, this);
}
/**
......@@ -98,34 +105,30 @@ export class GameStage extends Node {
/**
* 启动游戏
* @param config
* @param onAssetsProgress
* @param onAssetsComplete
* @param onPreloadAssetsProgress 预加载素材进度
* @param onPreloadAssetsComplete 预加载素材完成
* @param onStart
*/
async launch(config, onAssetsProgress?, onAssetsComplete?, onStart?) {
async launch(config, onPreloadAssetsProgress?, onPreloadAssetsComplete?, onStart?) {
this._config = config;
const {assets, customs} = config;
let loaded = 0;
let total = assets.length;
if (customs) {
for (let custom of customs) {
if (custom.assets) {
total += custom.assets.length;
}
}
}
await loadAssets(assets, p).catch(e => {
console.log(e);
});
if (customs) {
for (let custom of customs) {
if (custom.assets) {
await loadAssets(custom.assets, p).catch(e => {
console.log(e);
});
}
}
const {options: {env}, dataMapping, processes, builtinProcesses, customs} = this._config;
Stage.addUpdateObj(Tween);
injectEnv(env);
//registerScripts(scripts);
//registerCustomModuleFromConfig(customs);
registerCustomModules(customs);
if (dataMapping) {
this.dataCenter.registerDataMapping(dataMapping);
}
setProcessMetaLibs(processes, builtinProcesses);
await this.loadPreloadAssets(onPreloadAssetsProgress, onPreloadAssetsComplete);
this.start();
......@@ -134,50 +137,54 @@ export class GameStage extends Node {
onStart && onStart();
function p() {
loaded++;
onAssetsProgress && onAssetsProgress(loaded, total);
if (loaded >= total) {
onAssetsComplete && onAssetsComplete();
}
}
setTimeout(this.lazyLoadAllAssets,
this._config.options.lazyLoadWait || 1000);
}
/**
* 开始游戏
*/
start() {
const {options: {entrySceneView, env}, dataMapping, processes, builtinProcesses, scripts, customs} = this._config;
const {options: {entrySceneView, }, } = this._config;
Stage.addUpdateObj(Tween);
injectEnv(env);
//registerScripts(scripts);
//registerCustomModuleFromConfig(customs);
registerCustomModules(customs);
if (dataMapping) {
this.dataCenter.registerDataMapping(dataMapping);
}
setProcessMetaLibs(processes, builtinProcesses);
setTimeout(() => {
let sceneEntry = this.instantiateView(entrySceneView);
setTimeout(async () => {
let sceneEntry = await this.instantiateView(entrySceneView);
if (sceneEntry) {
this._sceneContainer.push(sceneEntry);
}
})
}
/**
* 显示加载视图
*/
async showInnerLoadingView() {
let loadingViewName = this._config.options.loadingView;
let loadingView = this._loadingView.getChildAt(0);
if (this._loadingView.children.length == 0 && loadingViewName) {
loadingView = await this.instantiateView(loadingViewName, true, false);
this._loadingView.addChild(loadingView);
}
this._loadingView.visible = true;
}
/**
* 隐藏加载视图
*/
hideInnerLoadingView() {
if (this._loadingView.visible) {
this._loadingView.visible = false;
}
}
/**
* 实例化视图
* @param name
* @param cache 如果开启缓存,就会以单例形式存在
* @param showLoadingView
*/
instantiateView(name, cache = true) {
async instantiateView(name, cache = true, showLoadingView = true) {
let view;
if (cache) {
view = this._viewCache[name];
......@@ -185,6 +192,39 @@ export class GameStage extends Node {
if (!view) {
let viewConfig = this.getViewConfigByName(name);
if (viewConfig) {
const {assets, customs} = this._config;
if (!Array.isArray(assets)) {
let groups = {};
let {depCustoms} = viewConfig;
if (depCustoms && depCustoms.length > 0) {
for (let custom of customs) {
if (depCustoms.indexOf(custom.id) >= 0 && custom.assets) {
if (!checkAssetGroupLoaded(custom.id)) {
groups[custom.id] = custom.assets;
}
}
}
}
if (!checkAssetGroupLoaded(viewConfig.uuid)) {
let depAssets = assets[viewConfig.uuid];
if (depAssets && depAssets.length > 0) {
groups[viewConfig.uuid] = depAssets;
}
}
if(Object.keys(groups).length > 0){
await loadAssetsGroups(groups, async () => {
if (showLoadingView) {
await this.showInnerLoadingView();
}
}, async () => {
if (showLoadingView) {
this.hideInnerLoadingView();
}
});
}
}
view = instantiate(viewConfig);
let store = {};
......@@ -196,9 +236,6 @@ export class GameStage extends Node {
view['$isViewRoot'] = true;
view['$_store'] = store;
/*let label = view.children[0];
label['z-for'] = 'item in list';*/
console.time('bind');
bind(store, view);
console.timeEnd('bind');
......@@ -221,28 +258,98 @@ export class GameStage extends Node {
return arrayFind(this._config.views, view => view.name === name);
}
/**
* 设置半透明层是否可见
* @param visible
*/
setBlackLayerVisible(visible) {
this._blackLayer.visible = visible;
}
onPopupContainerChange(e) {
const {action, view, options} = e.data;
onPopupContainerStart(e) {
const {action, view, lastView, options, hasView} = e.data;
const target = <StackContainer>e.target;
switch (action) {
case 'push':
case 'replace':
case 'popAll':
if (options && options.center) {
view.horizonCenter = 0;
view.verticalCenter = 0;
view.x = (target.width - view.width) / 2;
view.y = (target.height - view.height) / 2;
}
break;
}
this.setBlackLayerVisible(this._popupContainer.children.length > 0);
let blackLayer = this._blackLayer;
let pParent = blackLayer.parent;
if (hasView) {
target.addChildAt(blackLayer, target.childNum - 1 - (view ? 0 : 1));
let modalAlpha = 0.7;
if(options && options.hasOwnProperty('modalAlpha')){
modalAlpha = options.modalAlpha;
}
if (!pParent || blackLayer['tween_count'] > 0) {
blackLayer.alpha = 0;
Tween.get(blackLayer, null, null, true)
.to({alpha: modalAlpha}, 300);
}
} else if (pParent) {
Tween.get(blackLayer, null, null, true)
.to({alpha: 0}, 300)
.call(() => {
pParent.removeChild(blackLayer);
});
}
}
onPopupContainerComplete(e) {
}
lazyLoadAllAssets = async () => {
let {assets, customs} = this._config;
if (!Array.isArray(assets)) {
for (let uuid in assets) {
let group = assets[uuid];
if (group && group.length > 0) {
await loadAssetsGroup(group, uuid);
}
}
}
for (let custom of customs) {
let group = custom.assets;
if (group && group.length > 0) {
await loadAssetsGroup(group, custom.id);
}
}
};
async loadPreloadAssets(onPreloadAssetsProgress, onPreloadAssetsComplete){
const {assets, } = this._config;
let loaded = 0;
let assetsToLoad = assets;
let total;
if (!Array.isArray(assets)) { //如果是分组后的配置就加载共用分组,否则加载全部
assetsToLoad = assets['common'];
if(assetsToLoad.length > 0){
await this.showInnerLoadingView();
await loadAssetsGroups({
preload: assetsToLoad,
}, async () => {
}, async () => {
this.hideInnerLoadingView();
});
}
}else{
total = assetsToLoad.length;
await loadAssets(assetsToLoad, p).catch(e => {
console.log(e);
});
}
function p() {
loaded++;
onPreloadAssetsProgress && onPreloadAssetsProgress(loaded, total);
if (loaded >= total) {
onPreloadAssetsComplete && onPreloadAssetsComplete();
}
}
}
}
......@@ -4,6 +4,8 @@
import {DisplayObject} from "../../2d/display/index";
import {Node} from "./nodes/Node";
import {Event} from "../../2d/events/Event";
import {playViewEffect} from "./view-effects";
/**
* 栈式视图容器
......@@ -11,77 +13,214 @@ import {Node} from "./nodes/Node";
export class StackContainer extends Node {
private _mutex: boolean;
private _stack = [];
private _inserted = 0;
constructor(mutex = true) {
private _playing = false;
private _actionQueue = [];
constructor(mutex = true, inserted = 0) {
super();
this._mutex = mutex;
this._inserted = inserted;
this.percentWidth = 100;
this.percentHeight = 100;
this.mouseEnabled = false;
this.addEventListener(Event.START, () => {
this.mouseChildren = false;
});
this.addEventListener(Event.COMPLETE, () => {
this.mouseChildren = true;
});
}
get childNum() {
let len = this.children.length;
return len > 0 ? len - this._inserted : 0;
}
/**
* 推入视图
* @param view
* @param options
* @param dispatch
* @param playEffect
*/
push(view: DisplayObject, options?, dispatch = true) {
if (this._mutex && this.children.length > 0) {
this._stack.push(this.removeChildAt(0));
}
this.addChild(view);
if (dispatch) {
this.dispatchEvent('change', {action: 'push', view, options});
}
push(view: DisplayObject, options?, playEffect = true) {
this._actionQueue.push({action: 'push', args: arguments});
this._playNextAction();
}
/**
* 替换顶层视图
* @param view
* 撤出视图
* @param options
* @param playEffect
*/
replace(view: DisplayObject, options?) {
if (this.pop(false)) {
this.push(view, options, false);
this.dispatchEvent('change', {action: 'replace', view, options});
}
pop(options?, playEffect = true) {
this._actionQueue.push({action: 'pop', args: arguments});
this._playNextAction();
}
/**
* 撤出视图
* 替换顶层视图
* @param view
* @param options
* @param playEffect
*/
pop(dispatch = true) {
let len = this.children.length;
if (len <= 0) {
return false;
}
this.removeChildAt(len - 1);
if (this._mutex) {
this.addChild(this._stack.pop());
}
if (dispatch) {
this.dispatchEvent('change', {action: 'pop'});
}
return true;
replace(view: DisplayObject, options?, playEffect = true) {
this._actionQueue.push({action: 'replace', args: arguments});
this._playNextAction();
}
/**
* 撤出全部视图
* @param view
* @param options
* @param playEffect
*/
popAll(view?: DisplayObject, options?) {
this.removeChildren();
if (this._mutex) {
this._stack.splice(0);
popAll(view?: DisplayObject, options?, playEffect = true) {
this._actionQueue.push({action: 'popAll', args: arguments});
this._playNextAction();
}
private _playNextAction = () => {
if (this._playing || this._actionQueue.length === 0) {
return;
}
if (view) {
this.push(view, options, false);
let actionItem = this._actionQueue.shift();
let args = [];
for (let i = 0, li = actionItem.args.length; i < li; i++) {
const argument = actionItem.args[i];
args.push(argument);
}
this.dispatchEvent('change', {action: 'popAll', view, options});
this._playing = true;
this['_' + actionItem.action].apply(this, args)
.then(()=>{
this._playing = false;
setTimeout(this._playNextAction, 1);
});
};
private _push(view: DisplayObject, options?, playEffect = true) {
return new Promise(resolve => {
const action = 'push';
let lastView;
if (this._mutex && this.childNum > 0) {
lastView = this.getChildAt(0);
this._stack.push(lastView);
}
view.visible = false;
this.addChild(view);
let data = {action, view, lastView, options, hasView: true};
this.dispatchEvent(Event.START, data);
playViewEffect(
playEffect ? options ? options.effect : null : null,
options ? options.effectParams : {},
this._mutex, lastView, view, this,
() => {
this.dispatchEvent(Event.COMPLETE, data);
resolve();
}
)
})
}
private _pop(options?, playEffect = true) {
return new Promise(resolve => {
const action = 'pop';
let len = this.childNum;
if (len <= 0) {
return false;
}
let lastView = this.getChildAt(this.children.length - 1);
let view;
if (this._mutex) {
view = this._stack.pop();
view.visible = false;
this.addChild(view);
}
let data = {action, view, lastView, options, hasView: len > 1};
this.dispatchEvent(Event.START, data);
playViewEffect(
playEffect ? options ? options.effect : null : null,
options ? options.effectParams : {},
this._mutex, lastView, view, this,
() => {
this.dispatchEvent(Event.COMPLETE, data);
resolve();
}
)
})
}
private _replace(view: DisplayObject, options?, playEffect = true) {
return new Promise(resolve => {
const action = 'replace';
let len = this.childNum;
if (len <= 0) {
return false;
}
let lastView = this.getChildAt(len - 1);
view.visible = false;
this.addChild(view);
let data = {action, view, lastView, options, hasView: len > 1};
this.dispatchEvent(Event.START, data);
playViewEffect(
playEffect ? options ? options.effect : null : null,
options ? options.effectParams : {},
this._mutex, lastView, view, this,
() => {
this.dispatchEvent(Event.COMPLETE, data);
resolve();
}
)
})
}
private _popAll(view?: DisplayObject, options?, playEffect = true) {
return new Promise(resolve => {
const action = 'popAll';
let len = this.childNum;
if(len == 0){
resolve();
return;
}
let lastView = this.getChildAt(len);
while (this.children.length > 2) {
this.removeChildAt(0);
}
if (this._mutex) {
this._stack.splice(0);
}
if (view) {
view.visible = false;
this.addChild(view);
}
let data = {action, view, lastView, options, hasView: false};
this.dispatchEvent(Event.START, data);
playViewEffect(
playEffect ? options ? options.effect : null : null,
options ? options.effectParams : {},
this._mutex, lastView, view, this,
() => {
this.dispatchEvent(Event.COMPLETE, data);
resolve();
}
)
})
}
}
}
\ No newline at end of file
......@@ -3,8 +3,9 @@
*/
import {globalLoader} from "../../2d/loader/Loader";
import {arrayFind, linkScheme} from "../utils";
import {arrayFind, linkScheme} from "../utils/index";
import {parse} from "./bmp-text-manager";
import {globalEvent} from "../decorators/events";
let assetsConfig = [];
......@@ -22,10 +23,89 @@ const loaderMapping = {
'': 'Raw',
};
const assetGroupLoaded = {};
const assetGroupLoading = {};
/**
* 检查资源组是否已加载
* @param groupName
*/
export function checkAssetGroupLoaded(groupName) {
return assetGroupLoaded[groupName]
}
/**
* 加载多个素材组
* @param groups
* @param onStart
* @param onFinish
*/
export async function loadAssetsGroups(groups, onStart?, onFinish?) {
let total = 0;
let loaded = 0;
for (let groupName in groups) {
if (!checkAssetGroupLoaded(groupName)) {
let depAssets = groups[groupName];
if (depAssets && depAssets.length > 0) {
total += depAssets.length;
}
}
}
onStart && await onStart();
for (let groupName in groups) {
if (!checkAssetGroupLoaded(groupName)) {
let depAssets = groups[groupName];
if (depAssets && depAssets.length > 0) {
await loadAssetsGroup(depAssets, groupName, () => {
loaded++;
globalEvent.dispatchEvent('load-assets-process', {loaded, total})
}, () => {
globalEvent.dispatchEvent('load-assets-complete');
});
}
}
}
await new Promise(resolve => {
setTimeout(resolve, 100);
});
onFinish && await onFinish();
}
/**
* 加载素材组
*/
export async function loadAssetsGroup(config, groupName, onProcess?, onComplete?) {
if (checkAssetGroupLoaded[groupName]) {
return
}
if (assetGroupLoading[groupName]) {
return new Promise((resolve, reject) => {
assetGroupLoading[groupName].push({resolve, reject})
});
} else {
assetGroupLoading[groupName] = [];
}
await loadAssets(config, onProcess, onComplete);
assetGroupLoaded[groupName] = true;
for (let p of assetGroupLoading[groupName]) {
p.resolve();
}
delete assetGroupLoading[groupName];
}
/**
* 加载素材
*/
export function loadAssets(config, onProgress?, onComplete?) {
if (!config) {
console.log();
}
let total = config.length;
let loaded = 0;
let failedList = [];
......@@ -33,27 +113,36 @@ export function loadAssets(config, onProgress?, onComplete?) {
return Promise.all(
config.map(assetConfig => {
assetsConfig.push(assetConfig);
const {url, ext, uuid} = assetConfig;
const loadFunc = loaderMapping[ext];
if (loadFunc) {
if(url.indexOf(linkScheme) === 0){
loaded++;
onProgress && onProgress(loaded, total);
return Promise.resolve();
if (assetConfig.url.indexOf(linkScheme) === 0) {
let linkUUID = assetConfig.url.replace(linkScheme, '');
assetConfig = getAssetByUUID(linkUUID);
}
if (assetConfig) {
const {url, ext, uuid} = assetConfig;
const loadFunc = loaderMapping[ext];
if (loadFunc) {
let method = globalLoader['load' + loadFunc];
return method.call(globalLoader, url, uuid).then(
(data) => {
parse(assetConfig, data);
loaded++;
onProgress && onProgress(loaded, total);
},
(error) => {
failedList.push(url);
}
);
} else {
return p();
}
let method = globalLoader['load' + loadFunc];
return method.call(globalLoader, url, uuid).then(
(data) => {
parse(assetConfig, data);
loaded++;
onProgress && onProgress(loaded, total);
},
(error) => {
failedList.push(url);
}
);
} else {
return p();
}
function p() {
loaded++;
onProgress && onProgress(loaded, total);
return Promise.resolve();
......
/**
* Created by rockyl on 2020-05-04.
*/
import {Tween} from "../../2d/tween/Tween";
import {gameStage} from "../launcher";
import {injectProp} from "../utils/index";
import {Ease} from "../../2d/tween/Ease";
export function playViewEffect(name, params, mutex, lastView, view, container, callback) {
let effect = name ? effects[name] : effects.simple;
effect = effect || effects.simple;
effect(params || {}, mutex, lastView, view, container, callback);
}
const effects = {
simple(params, mutex, lastView, view, container, callback) {
if (mutex) {
container.removeChild(lastView);
} else {
if (lastView && !view) {
container.removeChild(lastView);
}
}
if (view) {
if (!view.parent) {
container.addChild(view);
}
view.visible = true;
}
callback();
},
fade(params, mutex, lastView, view, container, callback) {
const {duration = 300} = params;
if (mutex) {
fadeOut(() => {
fadeIn(callback);
})
} else {
if (lastView && !view) {
fadeOut(callback)
} else {
fadeIn(callback);
}
}
function fadeOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to({alpha: 0}, duration)
.call(() => {
container.removeChild(lastView);
lastView.alpha = 1;
callback();
});
} else {
callback();
}
}
function fadeIn(callback) {
if (view) {
view.visible = true;
view.alpha = 0;
Tween.get(view, null, null, true)
.to({alpha: 1}, params.duration || 300)
.call(() => {
callback();
});
} else {
callback();
}
}
},
flew(params, mutex, lastView, view, container, callback) {
const {duration = 300, direction = 'top', ease = 'backOut', inPos: inPosInput} = params;
const {stage: {width, height}} = gameStage;
let outPos: any = {};
switch (direction) {
case 'left':
outPos.x = -width;
break;
case 'right':
outPos.x = width;
break;
case 'top':
outPos.y = -height;
break;
case 'bottom':
outPos.y = height;
break;
}
let inEase = ease;
let outEase = ease ? ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out') : '';
if (mutex) {
flewOut(() => {
flewIn(callback);
})
} else {
if (lastView && !view) {
flewOut(callback)
} else {
flewIn(callback);
}
}
function flewOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to(outPos, duration, Ease[outEase])
.call(() => {
container.removeChild(lastView);
injectProp(lastView, outPos);
callback();
});
} else {
callback();
}
}
function flewIn(callback) {
if (view) {
let inPos: any = {
x: inPosInput && inPosInput.hasOwnProperty('x') ? inPosInput.x : view.x,
y: inPosInput && inPosInput.hasOwnProperty('y') ? inPosInput.y : view.y,
};
view.visible = true;
injectProp(view, outPos);
Tween.get(view, null, null, true)
.to(inPos, duration, Ease[inEase])
.call(() => {
callback();
});
} else {
callback();
}
}
},
hulu(params, mutex, lastView, view, container, callback) {
const {duration = 300, ease = 'backOut', x = 0, y = 0} = params;
let inEase = ease;
let outEase = ease ? ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out') : '';
let outPos = {
x: parseInt(x),
y: parseInt(y),
scaleX: 0, scaleY: 0,
};
if (mutex) {
huluOut(() => {
huluIn(callback);
})
} else {
if (lastView && !view) {
huluOut(callback)
} else {
huluIn(callback);
}
}
function huluOut(callback) {
if (lastView) {
outPos.x -= lastView.width / 2;
outPos.y -= lastView.height / 2;
Tween.get(lastView, null, null, true)
.to(outPos, duration, Ease[outEase])
.call(() => {
container.removeChild(lastView);
injectProp(lastView, {scaleX: 1, scaleY: 1});
callback();
});
} else {
callback();
}
}
function huluIn(callback) {
if (view) {
let inPos: any = {
x: view.x,
y: view.y,
scaleX: 1, scaleY: 1
};
outPos.x -= view.width / 2;
outPos.y -= view.height / 2;
view.visible = true;
injectProp(view, outPos);
Tween.get(view, null, null, true)
.to(inPos, duration, Ease[inEase])
.call(() => {
view.anchorX = 0;
view.anchorY = 0;
callback();
});
} else {
callback();
}
}
},
zoom(params, mutex, lastView, view, container, callback) {
const {duration = 300, ease = 'backOut'} = params;
let inEase = ease;
let outEase = ease ? ease.indexOf('Out') ? ease.replace('Out', 'In') : ease.replace('In', 'Out') : '';
if (mutex) {
zoomOut(() => {
zoomIn(callback);
})
} else {
if (lastView && !view) {
zoomOut(callback)
} else {
zoomIn(callback);
}
}
function zoomOut(callback) {
if (lastView) {
Tween.get(lastView, null, null, true)
.to({scaleX: 0, scaleY: 0}, duration, Ease[outEase])
.call(() => {
container.removeChild(lastView);
injectProp(view, {scaleX: 1, scaleY: 1});
callback();
});
} else {
callback();
}
}
function zoomIn(callback) {
if (view) {
view.anchorX = view.width / 2;
view.anchorY = view.height / 2;
view.visible = true;
injectProp(view, {scaleX: 0, scaleY: 0});
Tween.get(view, null, null, true)
.to({scaleX: 1, scaleY: 1}, duration, Ease[inEase])
.call(() => {
view.anchorX = 0;
view.anchorY = 0;
callback();
});
} else {
callback();
}
}
},
};
......@@ -103,9 +103,9 @@ export function dealPageRemainTime() {
}
}
export function accessLog(pagebizid, params?) {
export function accessLog(pageBizId, params?) {
let p = {
pagebizid,
pageBizId,
};
injectProp(p, params);
return httpRequest('buriedPoint', 'get', p);
......
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