Commit d316d012 authored by 任建锋's avatar 任建锋

--

parents be9ea4f9 94674e57
File added
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="FLOW" />
</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
This source diff could not be displayed because it is too large. You can view the blob instead.
<changelist name="Uncommitted_changes_before_Checkout_at_2020_5_15,_2_12_下午_[Default_Changelist]" date="1589523138013" recycled="false" toDelete="true">
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Checkout_at_2020_5_15,_2_12_下午_[Default_Changelist]/shelved.patch" />
<option name="DESCRIPTION" value="Uncommitted changes before Checkout at 2020/5/15, 2:12 下午 [Default Changelist]" />
</changelist>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
<changelist name="Uncommitted_changes_before_Update_at_2020_5_14,_2_47_下午_[Default_Changelist]" date="1589438835098" recycled="false" toDelete="true">
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Update_at_2020_5_14,_2_47_下午_[Default_Changelist]/shelved.patch" />
<option name="DESCRIPTION" value="Uncommitted changes before Update at 2020/5/14, 2:47 下午 [Default Changelist]" />
</changelist>
\ 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="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/debug/engine.js" beforeDir="false" afterPath="$PROJECT_DIR$/debug/engine.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/debug/engine.js.map" beforeDir="false" afterPath="$PROJECT_DIR$/debug/engine.js.map" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/2d/display/Container.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/2d/display/Container.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/zeroing/decorators/AlignManager.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/zeroing/decorators/AlignManager.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/zeroing/decorators/auto-adjust.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/zeroing/decorators/auto-adjust.ts" afterDir="false" />
</list>
<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="MarkDown" />
<option value="TypeScript File" />
<option value="JavaScript File" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="res-group" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="JsFlowSettings">
<service-enabled>true</service-enabled>
<exe-path />
<other-services-enabled>true</other-services-enabled>
<auto-save>true</auto-save>
</component>
<component name="ProjectId" id="1ZYzLmPKm3UfhIZLkr8RtiZwhUf" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/zeroing/game-warpper/mvvm" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
<property name="node.js.path.for.package.tslint" value="project" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.tslint" value="(autodetect)" />
<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="preferences.pluginManager" />
<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.dev" />
<item itemvalue="npm.preprocess" />
<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" />
<workItem from="1589536818547" duration="8764000" />
<workItem from="1589709011120" duration="341000" />
<workItem from="1589766926355" duration="379000" />
<workItem from="1589767318703" duration="29000" />
<workItem from="1589767471060" duration="25732000" />
<workItem from="1589853014410" duration="21858000" />
<workItem from="1589888428282" duration="5840000" />
<workItem from="1589990226868" duration="35000" />
<workItem from="1590026135813" duration="6205000" />
<workItem from="1590111768143" duration="10300000" />
</task>
<task id="LOCAL-00001" summary="11">
<created>1590043861171</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1590043861171</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="2" />
<option name="exactExcludedFiles">
<list>
<option value="$PROJECT_DIR$/examples/scripts/TouchZoom.js" />
<option value="$PROJECT_DIR$/examples/scripts/Wave.js" />
</list>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="1" />
<MESSAGE value="11" />
<option name="LAST_COMMIT_MESSAGE" value="11" />
</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 x="2248" y="-69" key="CommitChangelistDialog2" timestamp="1590043860892">
<screen x="1680" y="-229" width="1920" height="1177" />
</state>
<state x="2248" y="-69" key="CommitChangelistDialog2/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1590043860892" />
<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="318" height="907" key="GridCell.Tab.0.bottom" timestamp="1590066378412">
<screen x="35" y="23" width="1645" height="1027" />
</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="515" height="1057" key="GridCell.Tab.0.bottom/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1590043917163" />
<state width="687" height="907" key="GridCell.Tab.0.bottom/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1589767347615" />
<state width="318" height="907" key="GridCell.Tab.0.bottom/35.23.1645.1027@35.23.1645.1027" timestamp="1590066378412" />
<state width="318" height="907" key="GridCell.Tab.0.center" timestamp="1590066378411">
<screen x="35" y="23" width="1645" height="1027" />
</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="515" height="1057" key="GridCell.Tab.0.center/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1590043917161" />
<state width="687" height="907" key="GridCell.Tab.0.center/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1589767347614" />
<state width="318" height="907" key="GridCell.Tab.0.center/35.23.1645.1027@35.23.1645.1027" timestamp="1590066378411" />
<state width="318" height="907" key="GridCell.Tab.0.left" timestamp="1590066378411">
<screen x="35" y="23" width="1645" height="1027" />
</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="515" height="1057" key="GridCell.Tab.0.left/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1590043917159" />
<state width="687" height="907" key="GridCell.Tab.0.left/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1589767347614" />
<state width="318" height="907" key="GridCell.Tab.0.left/35.23.1645.1027@35.23.1645.1027" timestamp="1590066378411" />
<state width="318" height="907" key="GridCell.Tab.0.right" timestamp="1590066378411">
<screen x="35" y="23" width="1645" height="1027" />
</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="515" height="1057" key="GridCell.Tab.0.right/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1590043917162" />
<state width="687" height="907" key="GridCell.Tab.0.right/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1589767347615" />
<state width="318" height="907" key="GridCell.Tab.0.right/35.23.1645.1027@35.23.1645.1027" timestamp="1590066378411" />
<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="631" y="245" key="RollbackChangesDialog" timestamp="1589766990893">
<screen x="35" y="23" width="1645" height="1027" />
</state>
<state x="631" y="245" key="RollbackChangesDialog/35.23.1645.1027/1680.-229.1920.1177@35.23.1645.1027" timestamp="1589766990893" />
<state x="362" y="148" key="SettingsEditor" timestamp="1590043548896">
<screen x="35" y="23" width="1645" height="1027" />
</state>
<state x="362" y="148" key="SettingsEditor/35.23.1645.1027/1680.-229.1920.1177@1680.-229.1920.1177" timestamp="1590043548896" />
<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="36" width="670" height="676" key="search.everywhere.popup" timestamp="1590057778157">
<screen x="1680" y="-229" width="1920" height="1177" />
</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="1590057778157" />
<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" />
<state x="570" y="254" width="670" height="590" key="search.everywhere.popup/35.23.1645.1027@35.23.1645.1027" timestamp="1589767535433" />
</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
......@@ -63,6 +63,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
s.type = type;
delete s.data;
};
Event.MAYBE_ALIGN = "maybeAlign";
Event.RESIZE = "onResize";
Event.ON_SCROLL_TO_HEAD = "onScrollToHead";
Event.ON_SCROLL_STOP = "onScrollStop";
......@@ -332,12 +333,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
},
set: function (value) {
if (this._x !== value) {
if (value) {
this._x = value;
}
else {
this._x = 0;
}
this._x = value;
this.cb.call(this.scope);
}
},
......@@ -350,12 +346,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
},
set: function (value) {
if (this._y !== value) {
if (value) {
this._y = value;
}
else {
this._y = 0;
}
this._y = value;
this.cb.call(this.scope);
}
},
......@@ -786,32 +777,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Matrix.prototype.getRotation = function () {
return Math.round(Math.atan2(this.b, this.a) * RAD_TO_DEG);
};
Matrix.prototype.decompose = function (transform) {
var a = this.a;
var b = this.b;
var c = this.c;
var d = this.d;
var skewX = -Math.atan2(-c, d);
var skewY = Math.atan2(b, a);
var delta = Math.abs(skewX + skewY);
if (delta < 0.00001 || Math.abs(PI_2 - delta) < 0.00001) {
transform.rotation = skewY;
if (a < 0 && d >= 0) {
transform.rotation += (transform.rotation <= 0) ? Math.PI : -Math.PI;
}
transform.skew.x = transform.skew.y = 0;
}
else {
transform.rotation = 0;
transform.skew.x = skewX;
transform.skew.y = skewY;
}
transform.scale.x = Math.sqrt((a * a) + (b * b));
transform.scale.y = Math.sqrt((c * c) + (d * d));
transform.position.x = this.tx;
transform.position.y = this.ty;
return transform;
};
Matrix.prototype.toArray = function (transpose, out) {
if (transpose === void 0) { transpose = false; }
if (!this.array) {
......@@ -1670,135 +1635,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return MouseEvent;
}(Event));
function applyAutoAdjust(ctor) {
ctor.prototype.applyAutoAdjust = function () {
var adjustProxy = this.adjustProxy = new AdjustProxy(this);
this.addEventListener(Event.ADDED_TO_STAGE, adjustProxy.onAddedToStage, adjustProxy);
this.addEventListener(Event.REMOVED_FROM_STAGE, adjustProxy.onRemovedFromStage, adjustProxy);
};
var temp = new AdjustProxy(null);
var _loop_1 = function (key) {
Object.defineProperty(ctor.prototype, key, {
get: function () {
return this.adjustProxy.data[key];
},
set: function (v) {
var adjustProxy = this.adjustProxy;
if (adjustProxy.data[key] !== v) {
adjustProxy.data[key] = v;
adjustProxy.makeDirty();
}
},
enumerable: true,
configurable: true
});
};
for (var key in temp.data) {
_loop_1(key);
}
}
var AdjustProxy = (function () {
function AdjustProxy(host) {
this.data = {
percentWidth: NaN,
percentHeight: NaN,
left: NaN,
top: NaN,
right: NaN,
bottom: NaN,
horizonCenter: NaN,
verticalCenter: NaN,
};
this._host = host;
this.makeDirty();
}
AdjustProxy.prototype.makeDirty = function () {
this._sizeDirty = true;
};
AdjustProxy.prototype.onAddedToStage = function (e) {
this._host.parent.addEventListener(Event.RESIZE, this.onResize, this);
this._host.addEventListener(Event.RESIZE, this.onResize, this);
this._host.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, this);
};
AdjustProxy.prototype.onRemovedFromStage = function (e) {
this._host.removeEventListener(Event.RESIZE, this.onResize, this);
this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
};
AdjustProxy.prototype.setFrom = function (adjustProxy) {
for (var k in adjustProxy.data) {
this.data[k] = adjustProxy.data[k];
}
};
AdjustProxy.prototype.onResize = function (e) {
this._sizeDirty = true;
};
AdjustProxy.prototype.onEnterFrame = function (e) {
if (this._sizeDirty) {
this._sizeDirty = false;
this.adjustLayout();
}
};
AdjustProxy.prototype.adjustLayout = function () {
var that = this._host;
var _a = that.parent, pWidth = _a.width, pHeight = _a.height;
var width = that.width, height = that.height;
var _b = this.data, percentWidth = _b.percentWidth, percentHeight = _b.percentHeight, left = _b.left, top = _b.top, right = _b.right, bottom = _b.bottom, horizonCenter = _b.horizonCenter, verticalCenter = _b.verticalCenter;
var applyPercentWidth = function () {
if (t(percentWidth)) {
that.width = pWidth * percentWidth / 100;
}
};
var applyPercentHeight = function () {
if (t(percentHeight)) {
that.height = pHeight * percentHeight / 100;
}
};
var pw = true, ph = true;
if (t(horizonCenter)) {
applyPercentWidth();
that.x = (pWidth - that.width) / 2 + horizonCenter;
}
else {
if (t(left)) {
that.x = left;
if (t(right)) {
that.width = pWidth - left - right;
pw = false;
}
}
else if (t(right)) {
that.x = pWidth - width - right;
}
if (pw) {
applyPercentWidth();
}
}
if (t(verticalCenter)) {
applyPercentHeight();
that.y = (pHeight - that.height) / 2 + verticalCenter;
}
else {
if (t(top)) {
that.y = top;
if (t(bottom)) {
that.height = pHeight - top - bottom;
ph = false;
}
}
else if (t(bottom)) {
that.y = pHeight - height - bottom;
}
if (ph) {
applyPercentHeight();
}
}
};
return AdjustProxy;
}());
function t(v) {
return !isNaN(v) && v !== null && v !== undefined;
}
var ESCAPE_REG_EXP = /\$\{[\u4e00-\u9fa5_a-zA-Z0-9\|]+\}/g;
var linkedFlag = '$_linked_$';
var nodeScheme = 'node://';
......@@ -2052,6 +1888,223 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
}
function toBoolean(v) {
return !isNaN(v) && v !== null && v !== undefined;
}
var AlignManager = (function () {
function AlignManager() {
this.alignList = [];
}
AlignManager.prototype.flush = function () {
var _this = this;
var list = this.alignList;
list.forEach(function (v) {
_this.autoSize(v);
_this.align(v);
});
list.forEach(function (v) {
if (v.alignMode === ALIGN_MODE.ONCE) {
v.alignEnabled = false;
}
});
list.length = 0;
};
AlignManager.prototype.align = function (that) {
var _this = this;
if (!that.alignEnabled)
return;
var percentWidth = that.percentWidth, percentHeight = that.percentHeight, top = that.top, bottom = that.bottom, left = that.left, right = that.right, percentTop = that.percentTop, percentBottom = that.percentBottom, percentLeft = that.percentLeft, percentRight = that.percentRight, horizonCenter = that.horizonCenter, verticalCenter = that.verticalCenter;
var _a = that._width, tW_Z = _a === void 0 ? 0 : _a, _b = that._height, tH_Z = _b === void 0 ? 0 : _b;
var _c = (that.parent || {}), _d = _c._width, pW_Z = _d === void 0 ? 0 : _d, _e = _c._height, pH_Z = _e === void 0 ? 0 : _e;
var judgePL = toBoolean(percentLeft), judgePR = toBoolean(percentRight), judgePT = toBoolean(percentTop), judgePB = toBoolean(percentBottom);
var _left = judgePL ? percentLeft / 100 * pW_Z : left, _right = judgePR ? percentRight / 100 * pW_Z : right, _top = judgePT ? percentTop / 100 * pH_Z : top, _bottom = judgePB ? percentBottom / 100 * pH_Z : bottom;
if (toBoolean(_left) && toBoolean(_right)) {
that.x = _left;
that.width = pW_Z - _left - _right;
}
else {
toBoolean(percentWidth) && (tW_Z = that.width = pW_Z * percentWidth / 100);
if (toBoolean(horizonCenter)) {
that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter;
}
else if (toBoolean(_left)) {
that.x = _left;
}
else if (toBoolean(_right)) {
that.x = pW_Z - _right - tW_Z;
}
}
if (toBoolean(_top) && toBoolean(_bottom)) {
that.y = _top;
that.height = pH_Z - _top - _bottom;
}
else {
toBoolean(percentHeight) && (tH_Z = that.height = pH_Z * percentHeight / 100);
if (toBoolean(verticalCenter)) {
that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter;
}
else if (toBoolean(_top)) {
that.y = _top;
}
else if (toBoolean(_bottom)) {
that.y = pH_Z - _bottom - tH_Z;
}
}
that.children.forEach(function (v) { return _this.align(v); });
};
AlignManager.prototype.autoSize = function (that) {
var len = that.children.length;
if (len > 0) {
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
|| that.autoSizeMode === AUTO_SIZE_MODE.WIDTH
&& !toBoolean(that.percentWidth)) {
var maxR = 0;
for (var i = 0; i < len; i++) {
if (toBoolean(that.children[i].right))
continue;
var _x = that.children[i].x || 0;
var _w = that.children[i].__width || 0;
(_x + _w > maxR) ? maxR = _x + _w : 0;
}
that.width = maxR;
}
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
|| that.autoSizeMode === AUTO_SIZE_MODE.HEIGHT
&& !toBoolean(that.percentHeight)) {
var maxB = 0;
for (var i = 0; i < len; i++) {
if (toBoolean(that.children[i].bottom))
continue;
var _y = that.children[i].y || 0;
var _h = that.children[i].__height || 0;
(_y + _h > maxB) ? maxB = _y + _h : 0;
}
that.height = maxB;
}
}
};
AlignManager.prototype.addAlign = function (obj) {
var list = this.alignList;
if (list.indexOf(obj) < 0) {
list.push(obj);
}
};
return AlignManager;
}());
var alignMgr = new AlignManager();
function applyAutoAdjust(ctor) {
ctor.prototype.applyAutoAdjust = function () {
var adjustProxy = this.adjustProxy = new AdjustProxy(this);
this.addEventListener(Event.ADDED_TO_STAGE, adjustProxy.onAddedToStage, adjustProxy);
this.addEventListener(Event.REMOVED_FROM_STAGE, adjustProxy.onRemovedFromStage, adjustProxy);
};
var temp = new AdjustProxy(null);
var _loop_1 = function (key) {
if (key == 'alignMode'
|| key == 'autoSizeMode')
return "continue";
Object.defineProperty(ctor.prototype, key, {
get: function () {
return this.adjustProxy.data[key];
},
set: function (v) {
var adjustProxy = this.adjustProxy;
if (adjustProxy.data[key] !== v && !(isNaN(adjustProxy.data[key]) && isNaN(v))) {
adjustProxy.data[key] = v;
adjustProxy.makeDirty();
}
},
enumerable: true,
configurable: true
});
};
for (var key in temp.data) {
_loop_1(key);
}
Object.defineProperty(ctor.prototype, 'autoSizeMode', {
get: function () {
return this.adjustProxy.data['autoSizeMode'];
},
set: function (v) {
var adjustProxy = this.adjustProxy;
if (adjustProxy.data['autoSizeMode'] !== v) {
adjustProxy.data['autoSizeMode'] = v;
adjustProxy.makeDirty();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(ctor.prototype, 'alignMode', {
get: function () {
return this.adjustProxy.data['alignMode'];
},
set: function (v) {
var adjustProxy = this.adjustProxy;
if (adjustProxy.data['alignMode'] !== v) {
adjustProxy.data['alignMode'] = v;
adjustProxy.makeDirty();
if (v == ALIGN_MODE.ALWAYS)
this.alignEnabled = true;
}
},
enumerable: true,
configurable: true
});
}
var ALIGN_MODE;
(function (ALIGN_MODE) {
ALIGN_MODE["ONCE"] = "once";
ALIGN_MODE["ALWAYS"] = "always";
})(ALIGN_MODE || (ALIGN_MODE = {}));
var AUTO_SIZE_MODE;
(function (AUTO_SIZE_MODE) {
AUTO_SIZE_MODE["NONE"] = "none";
AUTO_SIZE_MODE["WIDTH"] = "width";
AUTO_SIZE_MODE["HEIGHT"] = "height";
AUTO_SIZE_MODE["ALL"] = "all";
})(AUTO_SIZE_MODE || (AUTO_SIZE_MODE = {}));
var AdjustProxy = (function () {
function AdjustProxy(host) {
this.data = {
percentWidth: NaN,
percentHeight: NaN,
left: NaN,
top: NaN,
right: NaN,
bottom: NaN,
percentLeft: NaN,
percentTop: NaN,
percentRight: NaN,
percentBottom: NaN,
horizonCenter: NaN,
verticalCenter: NaN,
autoSizeMode: AUTO_SIZE_MODE.NONE,
alignEnabled: true,
alignMode: ALIGN_MODE.ALWAYS,
};
this._host = host;
this.makeDirty();
}
AdjustProxy.prototype.makeDirty = function () {
this._host && alignMgr.addAlign(this._host);
this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty();
};
AdjustProxy.prototype.onAddedToStage = function (e) {
this._host.addEventListener(Event.MAYBE_ALIGN, this.makeDirty, this);
};
AdjustProxy.prototype.onRemovedFromStage = function (e) {
this._host.removeEventListener(Event.MAYBE_ALIGN, this.makeDirty);
};
AdjustProxy.prototype.setFrom = function (adjustProxy) {
for (var k in adjustProxy.data) {
this.data[k] = adjustProxy.data[k];
}
};
return AdjustProxy;
}());
function transPoint(str, sep) {
if (sep === void 0) { sep = ','; }
......@@ -3012,7 +3065,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
.then(function (result) {
return result;
}, function (e) {
console.log("[" + vm.id + "] terminate:", e);
if (log) {
console.log("[" + vm.id + "] terminate:", e);
}
});
}
......@@ -3127,6 +3182,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
function Container() {
var _this = _super.call(this) || this;
_this._mouseChildren = true;
_this.__width = 0;
_this.__height = 0;
_this._instanceType = "Container";
_this.children = [];
_this._transform = _this.transform;
......@@ -3147,6 +3204,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
Container.prototype.afterConstructor = function () {
};
Container.prototype.onChildrenChange = function (index) {
this.dispatchEvent(Event.MAYBE_ALIGN);
};
Container.prototype.attachVisibility = function () {
return;
......@@ -3265,27 +3323,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return this.getChildByPath(pathArr, 'getChildByName');
};
Container.prototype.getChildByIndexPath = function (path) {
if (path) {
var pathArr = path.split('/').map(function (seg) { return parseInt(seg); });
return this.getChildByPath(pathArr, 'getChildAt');
}
else {
return this;
}
};
Container.prototype.getIndexPath = function (untilNode) {
untilNode = untilNode || this.stage;
var node = this;
var path = [];
while (node.parent) {
var child = node;
node = node.parent;
path.unshift(node.getChildIndex(child));
if (node === untilNode) {
break;
}
}
return path.join('/');
var pathArr = path.split('/').map(function (seg) { return parseInt(seg); });
return this.getChildByPath(pathArr, 'getChildAt');
};
Container.prototype.findChildByUUID = function (uuid) {
if (this['uuid'] === uuid) {
......@@ -3439,7 +3478,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
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;
};
Container.prototype.hitTestPoint = function (globalPoint, isMouseEvent) {
if (isMouseEvent === void 0) { isMouseEvent = false; }
......@@ -3570,6 +3611,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this._localBoundsSelf.width = value;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right)))
? 0
: value;
}
},
enumerable: true,
......@@ -3590,11 +3635,41 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this._localBoundsSelf.height = value;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom)))
? 0
: value;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Container.prototype, "x", {
get: function () {
return this.position.x;
},
set: function (value) {
if (value == this.transform.position.x)
return;
this.transform.position.x = value;
this.dispatchEvent(Event.MAYBE_ALIGN);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Container.prototype, "y", {
get: function () {
return this.position.y;
},
set: function (value) {
if (value == this.transform.position.y)
return;
this.transform.position.y = value;
this.dispatchEvent(Event.MAYBE_ALIGN);
},
enumerable: true,
configurable: true
});
Container.prototype.clone = function (withEvents, withScripts) {
if (withEvents === void 0) { withEvents = false; }
if (withScripts === void 0) { withScripts = false; }
......@@ -5809,11 +5884,19 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this._width = undefined;
}
else {
value = abs(value);
var s = sign(this.scale.y) || 1;
this.scale.x = s * value / this._texture.orig.width;
this._width = value;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
if (isNaN(this.percentWidth) || this.percentWidth === null) {
this.__width = value;
}
else {
this.__width = 0;
}
}
},
enumerable: true,
......@@ -5831,11 +5914,19 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
this._height = undefined;
}
else {
value = abs(value);
var s = sign(this.scale.y) || 1;
this.scale.y = s * value / this._texture.orig.height;
this._height = value;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
if (isNaN(this.percentHeight) || this.percentHeight === null) {
this.__height = value;
}
else {
this.__height = 0;
}
}
},
enumerable: true,
......@@ -10410,6 +10501,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;
......@@ -11322,32 +11414,141 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
'.mp3': 'Sound',
'': 'Raw',
};
function loadAssets(config, onProgress, onComplete) {
var total = config.length;
var loaded = 0;
var failedList = [];
return Promise.all(config.map(function (assetConfig) {
assetsConfig.push(assetConfig);
var url = assetConfig.url, ext = assetConfig.ext, uuid = assetConfig.uuid;
var loadFunc = loaderMapping[ext];
if (loadFunc) {
if (url.indexOf(linkScheme) === 0) {
loaded++;
onProgress && onProgress(loaded, total);
return Promise.resolve();
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];
}
var method = globalLoader['load' + loadFunc];
return method.call(globalLoader, url, uuid).then(function (data) {
parse(assetConfig, data);
loaded++;
onProgress && onProgress(loaded, total);
}, function (error) {
failedList.push(url);
});
}
else {
loaded++;
onProgress && onProgress(loaded, total);
});
});
}
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 = [];
return Promise.all(config.map(function (assetConfig) {
assetsConfig.push(assetConfig);
if (assetConfig.url.indexOf(linkScheme) === 0) {
var linkUUID = assetConfig.url.replace(linkScheme, '');
assetConfig = getAssetByUUID(linkUUID);
}
if (assetConfig) {
var url_1 = assetConfig.url, ext = assetConfig.ext, uuid = assetConfig.uuid;
var loadFunc = loaderMapping[ext];
if (loadFunc) {
var method = globalLoader['load' + loadFunc];
return method.call(globalLoader, url_1, uuid).then(function (data) {
parse(assetConfig, data);
loaded++;
onProgress && onProgress(loaded, total);
}, function (error) {
failedList.push(url_1);
});
}
else {
return p();
}
}
else {
return p();
}
function p() {
loaded++;
onProgress && onProgress(loaded, total);
return Promise.resolve();
}
})).then(function () {
......@@ -14700,7 +14901,7 @@ 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',
......@@ -14727,6 +14928,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');
......@@ -14800,6 +15004,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right)))
? 0
: value;
}
},
enumerable: true,
......@@ -14825,6 +15033,10 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom)))
? 0
: value;
}
},
enumerable: true,
......@@ -15031,6 +15243,68 @@ 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 ";
......@@ -15225,6 +15499,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
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;
......@@ -15309,9 +15589,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
TextField.prototype._calculateBounds = function () {
var _a = this._localBoundsSelf, width = _a.width, height = _a.height;
<<<<<<< HEAD
var matrix = this.transform.worldMatrix;
this._bounds.x = matrix.tx;
this._bounds.y = matrix.ty;
=======
>>>>>>> 94674e57a616ffee254265568109dfb6e9d69533
this._bounds.width = width;
this._bounds.height = height;
};
......@@ -16698,58 +16981,413 @@ 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 {
if (lastView && !view) {
fadeOut(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, inPosInput = params.inPos;
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 ? 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: 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(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 ? 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 ? 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 <= 0) {
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 len = _this.childNum;
if (len == 0) {
resolve();
return;
}
var 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);
}
var data = { action: action, view: view, lastView: lastView, options: options, hasView: false };
_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));
......@@ -18922,6 +19560,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);
}
......@@ -18942,6 +19583,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);
};
......@@ -18977,9 +19621,12 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
if (url.indexOf('://') >= 0) {
if (url.indexOf(assetScheme) === 0) {
url = url.replace(assetScheme, '');
<<<<<<< HEAD
if (exports.editorMode) {
url = exports.assetResolver(url);
}
=======
>>>>>>> 94674e57a616ffee254265568109dfb6e9d69533
}
}
else {
......@@ -19626,29 +20273,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; }
......@@ -19671,37 +20330,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));
......@@ -20440,9 +21110,9 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
return sendData();
};
}
function accessLog(pagebizid, params) {
function accessLog(pageBizId, params) {
var p = {
pagebizid: pagebizid,
pageBizId: pageBizId,
};
injectProp(p, params);
return httpRequest('buriedPoint', 'get', p);
......@@ -20453,6 +21123,49 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
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;
......@@ -20461,20 +21174,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", {
......@@ -20505,57 +21222,30 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
enumerable: true,
configurable: true
});
GameStage.prototype.launch = function (config, onAssetsProgress, onAssetsComplete, onStart) {
GameStage.prototype.launch = function (config, onPreloadAssetsProgress, onPreloadAssetsComplete, onStart) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
function p() {
loaded++;
onAssetsProgress && onAssetsProgress(loaded, total);
if (loaded >= total) {
onAssetsComplete && onAssetsComplete();
}
}
var assets, customs, loaded, total, _i, customs_1, custom, _a, customs_2, custom;
var _a, env, dataMapping, processes, builtinProcesses, customs;
return tslib_1.__generator(this, function (_b) {
switch (_b.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;
}
}
_a = this._config, env = _a.options.env, dataMapping = _a.dataMapping, processes = _a.processes, builtinProcesses = _a.builtinProcesses, customs = _a.customs;
Stage.addUpdateObj(alignMgr);
Stage.addUpdateObj(Tween);
injectEnv(env);
registerCustomModules(customs);
if (dataMapping) {
this.dataCenter.registerDataMapping(dataMapping);
}
return [4, loadAssets(assets, p).catch(function (e) {
console.log(e);
})];
setProcessMetaLibs(processes, builtinProcesses);
return [4, this.loadPreloadAssets(onPreloadAssetsProgress, onPreloadAssetsComplete)];
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, loadAssets(custom.assets, p).catch(function (e) {
console.log(e);
})];
case 3:
_b.sent();
_b.label = 4;
case 4:
_a++;
return [3, 2];
case 5:
this.start();
dealPxEnv();
dealPageRemainTime();
onStart && onStart();
setTimeout(this.lazyLoadAllAssets, this._config.options.lazyLoadWait || 1000);
return [2];
}
});
......@@ -20563,70 +21253,222 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
};
GameStage.prototype.start = function () {
var _this = this;
var _a = this._config, _b = _a.options, entrySceneView = _b.entrySceneView, env = _b.env, dataMapping = _a.dataMapping, processes = _a.processes, builtinProcesses = _a.builtinProcesses, scripts = _a.scripts, customs = _a.customs;
Stage.addUpdateObj(Tween);
injectEnv(env);
registerCustomModules(customs);
if (dataMapping) {
this.dataCenter.registerDataMapping(dataMapping);
}
setProcessMetaLibs(processes, builtinProcesses);
setTimeout(function () {
var sceneEntry = _this.instantiateView(entrySceneView);
if (sceneEntry) {
_this._sceneContainer.push(sceneEntry);
}
var entrySceneView = this._config.options.entrySceneView;
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;
}
}
if (!(Object.keys(groups).length > 0)) return [3, 2];
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) {
};
GameStage.prototype.loadPreloadAssets = function (onPreloadAssetsProgress, onPreloadAssetsComplete) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
function p() {
loaded++;
onPreloadAssetsProgress && onPreloadAssetsProgress(loaded, total);
if (loaded >= total) {
onPreloadAssetsComplete && onPreloadAssetsComplete();
}
}
var assets, loaded, assetsToLoad, total;
var _this = this;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
assets = this._config.assets;
loaded = 0;
assetsToLoad = assets;
if (!!Array.isArray(assets)) return [3, 4];
assetsToLoad = assets['common'];
if (!(assetsToLoad.length > 0)) return [3, 3];
return [4, this.showInnerLoadingView()];
case 1:
_a.sent();
return [4, loadAssetsGroups({
preload: assetsToLoad,
}, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2];
});
}); }, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
this.hideInnerLoadingView();
return [2];
});
}); })];
case 2:
_a.sent();
_a.label = 3;
case 3: return [3, 6];
case 4:
total = assetsToLoad.length;
return [4, loadAssets(assetsToLoad, p).catch(function (e) {
console.log(e);
})];
case 5:
_a.sent();
_a.label = 6;
case 6: return [2];
}
});
});
};
return GameStage;
}(Node$1));
......@@ -20715,122 +21557,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
}
}
var propPrefixFilter = ['_', '__', '$'];
var includeProps = ['_width', '_height', 'worldMatrix'];
var excludeProps = ['eventTypes', 'eventTypes1', 'tempDisplayObjectParent', 'renderable', 'destroyed', 'children', 'start', 'pluginName', 'isUI', 'crossOrigin'];
var propTypeFilter = ['function', 'object'];
var offsetPrefix = 'offset_';
var absValueMapping = {
x: 'a',
y: 'd',
width: 'a',
height: 'd',
};
var absSelfValueMapping = {
x: 'X',
y: 'Y',
width: 'X',
height: 'Y',
};
var EditorStage = (function (_super) {
tslib_1.__extends(EditorStage, _super);
function EditorStage(stage) {
var _this = _super.call(this) || this;
_this._pos = new Point();
_this.name = 'editor-stage';
_this.percentWidth = 100;
_this.percentHeight = 100;
return _this;
}
EditorStage.prototype.launch = function (onStart) {
onStart();
};
EditorStage.prototype.showView = function (viewConfig) {
if (this._view) {
this.removeChild(this._view);
}
var view = this._view = instantiate(viewConfig);
this.addChild(view);
};
EditorStage.prototype.getNode = function (nodePath, origin) {
if (origin === void 0) { origin = false; }
var node = this._view.getChildByIndexPath(nodePath);
if (node) {
if (origin) {
return node;
}
else {
var node2 = {};
for (var key in node) {
var pass = false;
if (excludeProps.indexOf(key) >= 0) {
pass = true;
}
if (!pass) {
for (var _i = 0, propPrefixFilter_1 = propPrefixFilter; _i < propPrefixFilter_1.length; _i++) {
var prefix = propPrefixFilter_1[_i];
if (key.indexOf(prefix) >= 0) {
pass = true;
break;
}
}
}
var v = node[key];
if (propTypeFilter.indexOf(typeof v) >= 0) {
pass = true;
}
if (includeProps.indexOf(key) >= 0) {
pass = false;
}
if (pass) {
continue;
}
if (typeof v === 'object') {
v = objClone(v);
}
node2[key] = v;
}
return node2;
}
}
};
EditorStage.prototype.resizeStage = function () {
this.stage.resize();
};
EditorStage.prototype.modifyProps = function (nodePath, props) {
var node = this.getNode(nodePath, true);
if (node) {
for (var key in props) {
var v = props[key];
if (key.indexOf(offsetPrefix) < 0) {
node[key] = v;
}
else {
key = key.replace(offsetPrefix, '');
var offsetV = v / node.worldMatrix[absValueMapping[key]] * node['scale' + absSelfValueMapping[key]];
node[key] += offsetV;
}
}
node.adjustProxy.adjustLayout();
return true;
}
else {
console.warn('node not found:', nodePath);
return false;
}
};
EditorStage.prototype.getNodeWithPos = function (pos) {
var globalPos = this.stage.globalToLocal(pos, this._pos);
globalPos.x *= devicePixelRatio;
globalPos.y *= devicePixelRatio;
var node = this.hitTestPoint(globalPos, true);
console.log(globalPos.x, globalPos.y, node ? node.name : '');
return node;
};
return EditorStage;
}(Node$1));
exports.editorMode = false;
var alignManager = alignMgr;
function launch(url, loadingDelegate, onStart) {
if (queryParams.__proxy_mode__) {
return Promise.resolve('cancel launch');
......@@ -20866,33 +21593,24 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
case 1:
_a.sent();
return [4, new Promise(function (resolve) {
var _a = config.options, containerId = _a.containerId, designWidth = _a.designWidth, designHeight = _a.designHeight, frameRate = _a.frameRate, scaleMode = _a.scaleMode, rendererType = _a.rendererType, bgColor = _a.bgColor, autoResize = _a.autoResize, _editorMode = _a.editorMode, _assetResolver = _a.assetResolver;
exports.editorMode = _editorMode;
exports.assetResolver = _assetResolver;
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 () {
if (exports.editorMode) {
exports.editorStage = new EditorStage(stage);
stage.addChild(exports.editorStage);
exports.editorStage.launch(onStart);
}
else {
exports.gameStage = new GameStage(stage);
setGlobalContext({
gameStage: exports.gameStage
});
stage.addChild(exports.gameStage);
var delegate_1 = loadingDelegate || builtinLoadingView;
exports.gameStage.launch(config, function (done, total) {
delegate_1.onProgress && delegate_1.onProgress(done, total);
}, function () {
delegate_1.onComplete && delegate_1.onComplete();
}, onStart);
}
exports.gameStage = new GameStage(stage);
setGlobalContext({
gameStage: exports.gameStage
});
stage.addChild(exports.gameStage);
var delegate = loadingDelegate || builtinLoadingView;
exports.gameStage.launch(config, function (done, total) {
delegate.onProgress && delegate.onProgress(done, total);
}, function () {
delegate.onComplete && delegate.onComplete();
}, onStart);
});
resolve();
resolve(exports.gameStage);
})];
case 2: return [2, _a.sent()];
}
......@@ -20977,11 +21695,13 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.abs = abs;
exports.accessLog = accessLog;
exports.addCustomModule = addCustomModule;
exports.alignManager = alignManager;
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;
......@@ -21045,6 +21765,8 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.linkScheme = linkScheme;
exports.linkedFlag = linkedFlag;
exports.loadAssets = loadAssets;
exports.loadAssetsGroup = loadAssetsGroup;
exports.loadAssetsGroups = loadAssetsGroups;
exports.log10 = log10;
exports.log2 = log2;
exports.mapWebGLBlendModesToPixi = mapWebGLBlendModesToPixi;
......@@ -21089,6 +21811,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
exports.strLen = strLen;
exports.strShort = strShort;
exports.string2hex = string2hex;
exports.toBoolean = toBoolean;
exports.toDisplayDataURL = toDisplayDataURL;
exports.transPoint = transPoint;
exports.traverseViewNode = traverseViewNode;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{"id":"engine","url":"engine.a0a1c11664d9ed4ac76999a01ceb9a729e1b27c1.js"}
\ No newline at end of file
{"id":"engine","url":"engine.dee8bb73f7c234c7fe2527549add0fab7ca3d3fc.js"}
\ No newline at end of file
......@@ -12,7 +12,7 @@ const fs = require('fs');
const tslibWrapper = 'var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: __decorate,__param: __param,__metadata: __metadata,__awaiter: __awaiter,__generator: __generator,__exportStar: __exportStar,__values: __values,__read: __read,__spread: __spread,__spreadArrays: __spreadArrays,__await: __await,__asyncGenerator: __asyncGenerator,__asyncDelegator: __asyncDelegator,__asyncValues: __asyncValues,__makeTemplateObject: __makeTemplateObject,__importStar: __importStar,__importDefault: __importDefault};'
const tslibCode = fs.readFileSync(__dirname + '/scripts/tslib.min.js');
const options = {
export default {
input: 'src/index.ts',
output: [
{
......@@ -23,21 +23,16 @@ const options = {
tslib: 'tslib'
},
banner: tslibCode + '\n' + tslibWrapper,
}
},
],
plugins: [
progress(),
// progress(),
resolve({}),
typescript({
//useTsconfigDeclarationDir: true,
// useTsconfigDeclarationDir: true,
}),
commonjs(),
process.env.BUILD === 'production' && uglify({})
],
external: ['tslib'],
};
if(process.env.BUILD === 'production'){
options.plugins.push(uglify({}));
}
export default options;
......@@ -9,7 +9,7 @@ import {applyAutoAdjust} from "../../zeroing/decorators/auto-adjust";
import {applyScript} from "../../zeroing/decorators/scripts";
import {applyEvents} from "../../zeroing/decorators/events";
import {afterConstructor} from "../../zeroing/decorators/after-constructor";
import {injectProperties, instantiateScript} from "../../zeroing/utils/index";
import {injectProperties, instantiateScript, toBoolean} from "../../zeroing/utils/index";
import {isUI} from "../../zeroing/game-warpper/nodes/IUIComponent";
import Transform from "../math/Transform";
......@@ -510,16 +510,19 @@ export default class Container extends DisplayObject {
this._bounds.height = this._height;
}*/
if (widthSetted || heightSetted) {
const 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);
}
}
if (widthSetted || heightSetted) {
const 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);
return true;
}
return false;
}
/**
* 检测点是否在任何child上
......@@ -529,7 +532,7 @@ export default class Container extends DisplayObject {
//如果不可见
if (!this.visible) return null
//如果禁止子级的鼠标事件
if (isMouseEvent && !this.mouseChildren) {
if (isMouseEvent && !this.mouseChildren){
return this.hitTestSelf(globalPoint);
}
var children = this.children;
......@@ -720,65 +723,103 @@ export default class Container extends DisplayObject {
this.mouseChildren = false;
}
/**
* 一般用于获取宽高并设置
* 包括子级的,容器的尽量少用,子类可重写
* @member {number}
*/
get width(): number {
let value = this._width;
return !value && value != 0 ? this.scale.x * this.getLocalBounds().width : value;
}
/**
* 一般用于获取宽高并设置
* 包括子级的,容器的尽量少用,子类可重写
* @member {number}
*/
get width(): number {
let value = this._width;
return !value && value != 0 ? this.scale.x * this.getLocalBounds().width : value;
}
set width(value: number) {
// const width = this.getLocalBounds().width;
// if (width !== 0) {
// this.scale.x = value / width;
// } else {
// this.scale.x = 1;
// }
if (this._width !== value) {
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);
}
}
/**
* 高度同width
* @member {number}
*/
get height(): number {
let value = this._height;
return !value && value != 0 ? this.scale.y * this.getLocalBounds().height : value;
}
// if (width !== 0) {
// this.scale.x = value / width;
// } else {
// this.scale.x = 1;
// }
if (this._width !== value) {
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);
this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentWidth 或同时设置了 left 和 right 则表示他的宽度是相对的,则对于父级来说它的宽度永远是 0
this.__width = (toBoolean(this.percentWidth) || (toBoolean(this.left) && toBoolean(this.right)))
? 0
: value;
}
}
/**
* 高度同width
* @member {number}
*/
get height(): number {
let value = this._height;
return !value && value != 0 ? this.scale.y * this.getLocalBounds().height : value;
}
set height(value: number) {
// const height = this.getLocalBounds().height;
// if (height !== 0) {
// this.scale.y = value / height;
// } else {
// this.scale.y = 1;
// }
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);
}
}
// if (height !== 0) {
// this.scale.y = value / height;
// } else {
// this.scale.y = 1;
// }
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);
this.dispatchEvent(Event.MAYBE_ALIGN);
// 如果它设置了 percentHeight 或同时设置了 top 和 bottom 则表示他的高度是相对的,则对于父级来说它的高度永远是 0
this.__height = (toBoolean(this.percentHeight) || (toBoolean(this.top) && toBoolean(this.bottom)))
? 0
: value;
}
}
protected __width = 0; // 忽略 相对宽度 的 宽度,在父级计算自动宽度的时候用到
protected __height = 0; // 忽略 相对高度 的 高度,在父级计算自动高度的时候用到
get x(): number {
return this.position.x;
}
set x(value: number) {
if (value == this.transform.position.x) return;
this.transform.position.x = value;
this.dispatchEvent(Event.MAYBE_ALIGN);
}
get y(): number {
return this.position.y;
}
set y(value: number) {
if (value == this.transform.position.y) return;
this.transform.position.y = value;
this.dispatchEvent(Event.MAYBE_ALIGN);
}
clone(withEvents = false, withScripts = false) {
let target = this.constructor.apply(Object.create(this.constructor.prototype));
......
......@@ -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;
......@@ -385,52 +385,68 @@ export default class Sprite extends Container {
this.vertexTrimmedData = null;
}
/**
* 重写Container父类,废弃先
* texture的宽度和缩放乘积
* @member {number}
*/
get width() {
let value = this._width;
return !value && value != 0 ? Math.abs(this.scale.x) * this._texture.orig.width : value;
}
set 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);
}
}
/**
* texture的高度和缩放乘积
* @member {number}
*/
get height() {
let value = this._height;
return !value && value != 0 ? Math.abs(this.scale.y) * this._texture.orig.height : value;
}
set 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);
}
}
/**
* 重写Container父类,废弃先
* texture的宽度和缩放乘积
* @member {number}
*/
get width() {
let value = this._width;
return !value && value != 0 ? Math.abs(this.scale.x) * this._texture.orig.width : value;
}
set width(value) {
if (this._width !== value) {
if (!value && value != 0) {
this.scale.x = 1;
this._width = undefined;
} else {
value = abs(value);
const s = sign(this.scale.y) || 1;
this.scale.x = s * value / this._texture.orig.width;
this._width = value;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
if (isNaN(this.percentWidth) || this.percentWidth === null) {
this.__width = value;
} else {
this.__width = 0;
}
}
}
/**
* texture的高度和缩放乘积
* @member {number}
*/
get height() {
let value = this._height;
return !value && value != 0 ? Math.abs(this.scale.y) * this._texture.orig.height : value;
}
set height(value) {
if (this._height !== value) {
if (!value && value != 0) {
this.scale.y = 1;
this._height = undefined;
} else {
value = abs(value);
const s = sign(this.scale.y) || 1;
this.scale.y = s * value / this._texture.orig.height;
this._height = value;
}
this.dispatchEvent(Event.RESIZE);
this.dispatchEvent(Event.MAYBE_ALIGN);
if (isNaN(this.percentHeight) || this.percentHeight === null) {
this.__height = value;
} else {
this.__height = 0;
}
}
}
/**
* 0,0标识左上角,0.5,0.5表示中间,1,1表示右下角
......
......@@ -559,7 +559,9 @@ export class Stage extends Container {
* @return {{w: number, h: number}}
*/
public getRootDivWH(div: HTMLDivElement) {
/*let iw = document.body.clientWidth;
/*let sw = div.style.width;
let sh = div.style.height;
let iw = document.body.clientWidth;
// let ih = document.body.clientHeight-40;
let ih = document.body.clientHeight;
let vW = parseInt(sw);
......
......@@ -9,9 +9,10 @@ import {HashObject} from "../HashObject";
*/
export class Event extends HashObject {
// public static IMAGE_LOADED: string = "onImageLoaded"
public static MAYBE_ALIGN: string = "maybeAlign";
/**
// public static IMAGE_LOADED: string = "onImageLoaded"
/**
* 舞台尺寸发生变化时触发
* @Event
* @property RESIZE
......
......@@ -1344,6 +1344,8 @@ export default class Graphics extends Container {
} else {
this._texture.baseTexture.update();
}
//@ts-ignore
this._texture.onBaseTextureUpdated({target:this._texture.baseTexture})
//可能需要更改_texture,this._texture.baseTexture尺寸
this.offsetX = bounds.x;
......
import {SCALE_MODES, TEXT_ALIGN, TEXT_lINETYPE, VERTICAL_ALIGN} from "../const";
import Texture from "../texture/Texture";
import {getRGBA, hex2string} from "../utils/index";
import {Rectangle} from "../math/index";
import {ObservablePoint, Rectangle} from "../math/index";
import Sprite from "../display/Sprite";
import {Event} from "../events/index";
//文本canvas上xy的偏移量
const padding = 10;
const padding = 50;
const styleFields = {
color: 'fillStyle',
......@@ -500,6 +500,86 @@ export class TextField extends Sprite {
private _border: boolean = false;
/**
* 设置或获取阴影颜色
* @property property
* @public
* @since 1.0.6
* @param value
*/
public set shadowColor(value: string) {
if (this._shadowColor != value) {
this._shadowColor = value;
this.dirty = true;
}
}
public get shadowColor(): string {
return this._shadowColor;
}
private _shadowColor: string = '#000';
/**
* 设置或获取阴影模糊度
* @property property
* @public
* @since 1.0.6
* @param value
*/
public set shadowBlur(value: number) {
if (this._shadowBlur != value) {
this._shadowBlur = value;
this.dirty = true;
}
}
public get shadowBlur(): number {
return this._shadowBlur;
}
private _shadowBlur: number = 0;
/**
* 设置或获取阴影偏移
* @property property
* @public
* @since 1.0.6
* @param value
*/
public set shadowOffset(value: ObservablePoint) {
if (this._shadowOffset != value) {
this._shadowOffset = value;
this.dirty = true;
}
}
public get shadowOffset(): ObservablePoint {
return this._shadowOffset;
}
get shadowOffsetX(): number {
return this.position.x;
}
set shadowOffsetX(value: number) {
this._shadowOffset.x = value;
}
get shadowOffsetY(): number {
return this.position.y;
}
set shadowOffsetY(value: number) {
this._shadowOffset.y = value;
}
private _shadowOffset: ObservablePoint = new ObservablePoint(this.onShadowOffsetChange, this);
private onShadowOffsetChange() {
this.dirty = true;
}
private _setupFont(font, size, bold, italic) {
let fontStyle: any = size;
fontStyle += "px ";
......@@ -625,7 +705,7 @@ export class TextField extends Sprite {
s.realLines = realLines;
s._prepContext(ctx);
let textWidth = !s._width && s._width != 0 ? 0 : s._width;
let textWidth = s._width;
// let lineH = s._lineSpacing + s.size;
//单行文本时
if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
......@@ -653,7 +733,7 @@ export class TextField extends Sprite {
}
} else {
//textWidth取每行最大值,如果没设置过textWidth
const shouldMeasureTextWidth = !s._width && s._width != 0 ? true : false;
const shouldMeasureTextWidth = !s._width && s._width != 0;
let index = 0;
for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i];
......@@ -665,7 +745,7 @@ export class TextField extends Sprite {
index++;
}
if (shouldMeasureTextWidth) {
textWidth = Math.max(lineWidth, textWidth);
textWidth = lineWidth;
}
}
index = 0;
......@@ -742,6 +822,12 @@ export class TextField extends Sprite {
}
}
ctx.setTransform(1, 0, 0, 1, tx + padding, padding);
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);
let lineH = s._lineSpacing + s.size;
//如果有_textHeight,就需要应用竖直对齐
......
import { ALIGN_MODE, AUTO_SIZE_MODE } from "./auto-adjust";
import { toBoolean } from "../utils/utils";
import { Container } from "../../2d/display/index";
/**
* 自适应管理器
* @constructor
*/
class AlignManager {
// 这个列表里的对象会在渲染前被自动调整
private alignList = [];
constructor() {
}
/**
* flash (渲染前)
*/
public flush() {
const list = this.alignList;
list.forEach((v: Container) => {
this.autoSize(v); // 去调整大小
this.align(v); // 去自动对齐
});
// 要在这里单独检查,因为对齐一次后可能遇到其父节点需要对齐导致其再对齐一次
list.forEach((v) => {
if (v.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
v.alignEnabled = false;
}
});
// 干掉列表
list.length = 0;
}
/**
* align
* @param that
*/
private align(that) {
if (!that.alignEnabled) return; // 如果的自动对齐关闭里则啥也不干
// if(that.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
// that.alignEnabled = false;
// }
const {
percentWidth, percentHeight,
top, bottom, left, right,
percentTop, percentBottom, percentLeft, percentRight,
horizonCenter, verticalCenter
} = that;
let {_width: tW_Z = 0, _height: tH_Z = 0} = that;
const {_width: pW_Z = 0, _height: pH_Z = 0} = (that.parent || {});
/// TODO null / 100 == 0 ?????? wtf!!!! 我裂开了
// percentWidth /= 100;
// percentHeight /= 100;
// percentTop /= 100;
// percentBottom /= 100;
// percentLeft /= 100;
// percentRight /= 100;
const judgePL = toBoolean(percentLeft)
, judgePR = toBoolean(percentRight)
, judgePT = toBoolean(percentTop)
, judgePB = toBoolean(percentBottom);
// 先转化一下
const _left = judgePL ? percentLeft / 100 * pW_Z : left
, _right = judgePR ? percentRight / 100 * pW_Z : right
, _top = judgePT ? percentTop / 100 * pH_Z : top
, _bottom = judgePB ? percentBottom / 100 * pH_Z : bottom;
/**
* 计算 width 和 x 值
*/
if (toBoolean(_left) && toBoolean(_right)) { // _left _right 都有则直接拉伸或缩小
that.x = _left;
that.width = pW_Z - _left - _right;
} else {
// 先设置下自己的 width
toBoolean(percentWidth) && (tW_Z = that.width = pW_Z * percentWidth / 100);
// 先考虑 horizonCenter 属性
if (toBoolean(horizonCenter)) {
// x 值 = 父节点的中间值 - 自己宽度的一半 - 居中差值
that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter;
} else if (toBoolean(_left)) { // 假如有 _left
that.x = _left;
} else if (toBoolean(_right)) { // 假如有 _right
that.x = pW_Z - _right - tW_Z;
}
}
/**
* 计算 height 和 y 值
*/
if (toBoolean(_top) && toBoolean(_bottom)) { // _top _bottom 都有则直接拉伸或缩小
that.y = _top;
that.height = pH_Z - _top - _bottom;
} else {
// 先设置下自己的 height
toBoolean(percentHeight) && (tH_Z = that.height = pH_Z * percentHeight / 100);
// 先考虑 horizonCenter 属性
if (toBoolean(verticalCenter)) {
// x 值 = 父节点的中间值 - 自己高度的一半 - 居中差值
that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter;
} else if (toBoolean(_top)) { // 假如有 _top
that.y = _top;
} else if (toBoolean(_bottom)) { // 假如有 _bottom
that.y = pH_Z - _bottom - tH_Z;
}
}
that.children.forEach(v => this.align(v));
}
/**
* 自动大小
* @param that
*/
private autoSize(that) {
const len = that.children.length
if (len > 0) {
// 检测本身的是否是可以自动宽
// if (that.autoWidth
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
|| that.autoSizeMode === AUTO_SIZE_MODE.WIDTH
// && !toBoolean(that.right) /// TODO 我把它注释了 注释这行可以让容器设置了 right 后反向撑开,保持 right 边距不变
&& !toBoolean(that.percentWidth)) {
/// TODO 下面这段注释的代码可以实现让其左边撑开,不过还有未知bug
// 找出子节点最小x
// let minX = 0;
// for(let i = 0; i < len; i++) {
// if(that.children[i].x < minX) {
// minX = that.children[i].x;
// }
// }
// if(minX < 0) {
// that.children.forEach(v => v.x -= minX);
// that.x += minX;
// that.width -= minX;
// }
// 找出最右值
let maxR = 0;
for (let i = 0; i < len; i++) {
if (toBoolean(that.children[i].right)) continue; /// TODO 开启这个,忽略带 right 值的子节点
let _x = that.children[i].x || 0;
let _w = that.children[i].__width || 0;
(_x + _w > maxR) ? maxR = _x + _w : 0;
}
that.width = maxR;
}
// 检测本身的是否是可以自动高
if (that.autoSizeMode === AUTO_SIZE_MODE.ALL
|| that.autoSizeMode === AUTO_SIZE_MODE.HEIGHT
// && !toBoolean(that.bottom) /// TODO 我把它注释了 注释这行可以让容器设置了 bottom 后反向撑开,保持 bottom 边距不变
&& !toBoolean(that.percentHeight)) {
/// TODO 下面这段注释的代码可以实现让其上边撑开,不过还有未知bug
// 找出子节点最小y
// let minY = 0;
// for(let i = 1; i < len; i++) {
// if(that.children[i].y < minY) {
// minY = that.children[i].y;
// }
// }
// if(minY < 0) {
// that.children.forEach(v => v.y -= minY);
// that.y += minY;
// that.height -= minY;
// }
// 找出最下值
let maxB = 0;
for (let i = 0; i < len; i++) {
if (toBoolean(that.children[i].bottom)) continue; /// TODO 开启这个,忽略带 bottom 值的子节点
let _y = that.children[i].y || 0;
let _h = that.children[i].__height || 0;
(_y + _h > maxB) ? maxB = _y + _h : 0;
}
that.height = maxB;
}
}
}
/**
* 添加一个变脏的对象
* @param obj
*/
public addAlign(obj) {
const list = this.alignList;
if (list.indexOf(obj) < 0) {
list.push(obj);
}
}
}
function tt(...v) {
for (let i = 0; i < v.length; i++) {
if (!toBoolean(v[i])) return false;
}
return true;
}
export let alignMgr = new AlignManager();
......@@ -4,151 +4,328 @@
* 自适应功能
*/
import {Event} from "../../2d/events/index";
import { Event } from "../../2d/events/index";
import { alignMgr } from "./AlignManager";
/**
* 应用自适应
* @param ctor
*/
export function applyAutoAdjust(ctor: Function) {
ctor.prototype.applyAutoAdjust = function () {
let adjustProxy = this.adjustProxy = new AdjustProxy(this);
this.addEventListener(Event.ADDED_TO_STAGE, adjustProxy.onAddedToStage, adjustProxy);
this.addEventListener(Event.REMOVED_FROM_STAGE, adjustProxy.onRemovedFromStage, adjustProxy);
};
let temp = new AdjustProxy(null);
for (let key in temp.data)
Object.defineProperty(ctor.prototype, key, {
get: function () {
return this.adjustProxy.data[key];
},
set: function (v) {
const adjustProxy: AdjustProxy = this.adjustProxy;
if (adjustProxy.data[key] !== v) {
adjustProxy.data[key] = v;
adjustProxy.makeDirty();
}
},
enumerable: true,
configurable: true
});
ctor.prototype.applyAutoAdjust = function() {
let adjustProxy = this.adjustProxy = new AdjustProxy(this);
this.addEventListener(Event.ADDED_TO_STAGE, adjustProxy.onAddedToStage, adjustProxy);
this.addEventListener(Event.REMOVED_FROM_STAGE, adjustProxy.onRemovedFromStage, adjustProxy);
};
let temp = new AdjustProxy(null);
for (let key in temp.data) {
if (key == 'alignMode'
|| key == 'autoSizeMode') continue;
Object.defineProperty(ctor.prototype, key, {
get: function() {
return this.adjustProxy.data[key];
},
set: function(v) {
const adjustProxy: AdjustProxy = this.adjustProxy;
if (adjustProxy.data[key] !== v && !(isNaN(adjustProxy.data[key]) && isNaN(v))) {
adjustProxy.data[key] = v;
adjustProxy.makeDirty();
}
},
enumerable: true,
configurable: true
});
}
Object.defineProperty(ctor.prototype, 'autoSizeMode', {
get: function() {
return this.adjustProxy.data['autoSizeMode'];
},
set: function(v) {
const adjustProxy: AdjustProxy = this.adjustProxy;
if (adjustProxy.data['autoSizeMode'] !== v) {
adjustProxy.data['autoSizeMode'] = v;
adjustProxy.makeDirty();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(ctor.prototype, 'alignMode', {
get: function() {
return this.adjustProxy.data['alignMode'];
},
set: function(v) {
const adjustProxy: AdjustProxy = this.adjustProxy;
if (adjustProxy.data['alignMode'] !== v) {
adjustProxy.data['alignMode'] = v;
adjustProxy.makeDirty();
if (v == ALIGN_MODE.ALWAYS) this.alignEnabled = true; // 如果设置为 always 则自动开启
}
},
enumerable: true,
configurable: true
});
}
export enum ALIGN_MODE {
ONCE = 'once',
ALWAYS = 'always',
}
export enum AUTO_SIZE_MODE {
NONE = 'none',
WIDTH = 'width',
HEIGHT = 'height',
ALL = 'all',
}
/**
* 自适应数据
*/
class AdjustProxy {
data = {
percentWidth: NaN,
percentHeight: NaN,
left: NaN,
top: NaN,
right: NaN,
bottom: NaN,
horizonCenter: NaN,
verticalCenter: NaN,
};
private _host;
private _sizeDirty;
constructor(host) {
this._host = host;
this.makeDirty();
}
makeDirty() {
this._sizeDirty = true;
}
onAddedToStage(e) {
this._host.parent.addEventListener(Event.RESIZE, this.onResize, this);
this._host.addEventListener(Event.RESIZE, this.onResize, this);
this._host.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, this);
}
onRemovedFromStage(e) {
//this._host.parent.removeEventListener(Event.RESIZE, this.onResize);
this._host.removeEventListener(Event.RESIZE, this.onResize, this);
this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
}
setFrom(adjustProxy: AdjustProxy) {
for (let k in adjustProxy.data) {
this.data[k] = adjustProxy.data[k];
}
}
private onResize(e) {
this._sizeDirty = true;
}
private onEnterFrame(e) {
if (this._sizeDirty) {
this._sizeDirty = false;
this.adjustLayout();
}
}
adjustLayout() {
const that = this._host;
const {width: pWidth, height: pHeight} = that.parent;
const {width, height} = that;
const {percentWidth, percentHeight, left, top, right, bottom, horizonCenter, verticalCenter} = this.data;
const applyPercentWidth = function () {
if (t(percentWidth)) {
that.width = pWidth * percentWidth / 100;
}
};
const applyPercentHeight = function () {
if (t(percentHeight)) {
that.height = pHeight * percentHeight / 100;
}
};
let pw = true, ph = true;
if (t(horizonCenter)) {
applyPercentWidth();
that.x = (pWidth - that.width) / 2 + horizonCenter;
} else {
if (t(left)) {
that.x = left;
if (t(right)) {
that.width = pWidth - left - right;
pw = false;
}
} else if (t(right)) {
that.x = pWidth - width - right;
}
if (pw) {
applyPercentWidth();
}
}
if (t(verticalCenter)) {
applyPercentHeight();
that.y = (pHeight - that.height) / 2 + verticalCenter;
} else {
if (t(top)) {
that.y = top;
if (t(bottom)) {
that.height = pHeight - top - bottom;
ph = false;
}
} else if (t(bottom)) {
that.y = pHeight - height - bottom;
}
if (ph) {
applyPercentHeight();
}
}
}
data = {
percentWidth: NaN,
percentHeight: NaN,
}
left: NaN,
top: NaN,
right: NaN,
bottom: NaN,
percentLeft: NaN,
percentTop: NaN,
percentRight: NaN,
percentBottom: NaN,
horizonCenter: NaN,
verticalCenter: NaN,
autoSizeMode: AUTO_SIZE_MODE.NONE,
// autoWidth: false,
// autoHeight: false,
alignEnabled: true,
alignMode: ALIGN_MODE.ALWAYS,
};
private _host;
// private _sizeDirty = false;
constructor(host) {
this._host = host;
this.makeDirty();
}
makeDirty() {
// if (this._sizeDirty) return;
// this._sizeDirty = true;
this._host && alignMgr.addAlign(this._host);
this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty();
}
// resetDirty() {
// this._sizeDirty = false;
// }
onAddedToStage(e) {
this._host.addEventListener(Event.MAYBE_ALIGN, this.makeDirty, this);
// this._host.parent.addEventListener(Event.MAYBE_ALIGN, this.align, this);
// this._host.parent.addEventListener(Event.RESIZE, this.align, this);
// this._host.addEventListener(Event.RESIZE, this.align, this);
// this._host.addEventListener(Event.ENTER_FRAME, this.onEnterFrame, this);
}
onRemovedFromStage(e) {
this._host.removeEventListener(Event.MAYBE_ALIGN, this.makeDirty);
// this._host.parent.removeEventListener(Event.MAYBE_ALIGN, this.align);
// this._host.parent.removeEventListener(Event.RESIZE, this.align);
// this._host.removeEventListener(Event.RESIZE, this.align, this);
// this._host.removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
}
setFrom(adjustProxy: AdjustProxy) {
for (let k in adjustProxy.data) {
this.data[k] = adjustProxy.data[k];
}
}
// /**
// * align 方式 T + 1
// * @param e
// */
// private readyAlign(e) {
// if (this._sizeDirty == true) {
// return;
// }
// this._sizeDirty = true;
// this._host && alignMgr.addAlign(this._host);
// this._host && this._host.parent && this._host.parent.adjustProxy.makeDirty(); // 它爸爸也要设置一次。可能有autoSize
// }
// autoSize() {
// let that = this._host.parent;
// if(that.name !== 'rect1' && that.name !== 'rect_main' && that.name !== 'rect2' && that.name !== 'rect3') return;
//
// if(that.name == "scene-container"
// || that.name == "game-stage"
// || that.name == "main")
// return;
//
// // 检测本身的是否是自动宽高
// let len = that.children.length
// if(len > 0) {
// // if(that._autoWidth) {
// // 找出子节点最小x
// // let minX = that.children[0].x;
// // for(let i = 1; i < len; i++) {
// // if(that.children[i].x < minX) {
// // minX = that.children[i].x;
// // }
// // }
// // that.children.forEach(v => v._x -= minX);
// // that._x += minX;
//
// // 找出右值
// let max = 0;
// for(let i = 0; i < len; i++) {
// if(t(that.children[i].right)) continue;
// let _x = that.children[i].x || 0;
// let _w = that.children[i].__width || 0;
// if(_x + _w > max) {
// max = _x + _w;
// }
// }
// that.width = max;
// // let dw = that.width - max;
// // that._width -= dw;
// // }
//
// // if(that._autoHeight) {
// // 找出子节点最小y
// // let minY = that.children[0].y;
// // for(let i = 1; i < len; i++) {
// // if(that.children[i].x < minY) {
// // minY = that.children[i].y;
// // }
// // }
// // that.children.forEach(v => v._y -= minY);
// // that._y += minY;
//
// // 找出右值
// max = 0;
// for(let i = 0; i < len; i++) {
// if(t(that.children[i].bottom)) continue;
// let _y = that.children[i].y || 0;
// let _h = that.children[i].__height || 0;
// if(_y + _h > max) {
// max = _y + _h;
// }
// }
// that.height = max;
// // let dh = that.height - max;
// // that._height -= dh;
// // }
// }
//
// }
// private onEnterFrame(e) {
// if(this._sizeDirty) {
// this._sizeDirty = false;
//
// // this.adjustLayout();
// }
// }
function t(v) {
return !isNaN(v) && v !== null && v !== undefined;
// /**
// * 手动调用可在当前帧 align
// */
// adjustLayout() {
// // return;
//
// const that = this._host;
//
// if(!that.alignEnabled) return;
//
// if(that.alignMode === ALIGN_MODE.ONCE) { // 如果是单次对齐则一次运算之后就关闭它
// that.alignEnabled = false;
// }
//
// const {percentWidth, percentHeight, left, top, right, bottom, horizonCenter, verticalCenter} = this.data;
//
// let {_width: tW_Z = 0, _height: tH_Z = 0} = that;
// const {_width: pW_Z = 0, _height: pH_Z = 0} = that.parent;
//
// let {_width: tW, _height: tH} = that;
// const {_width: pW, _height: pH} = that.parent;
// this.autoSize();
//
// /**
// * 计算 width 和 x 值
// */
// if(t(left) && t(right)) { // left right 都有则直接拉伸或缩小
//
// that.x = left;
//
// that.width = pW_Z - left - right;
//
// } else {
// // 先设置下自己的 width
// t(percentWidth) && (tW_Z = that.width = pW_Z * percentWidth / 100);
//
// // 先考虑 horizonCenter 属性
// if(t(horizonCenter)) {
// // x 值 = 父节点的中间值 - 自己宽度的一半 - 居中差值
// that.x = pW_Z / 2 - tW_Z / 2 + horizonCenter;
//
// } else if(t(left)) { // 假如有左边距
//
// that.x = left;
//
// } else if(t(right)) { // 假如有右边距
//
// that.x = pW_Z - right - tW_Z;
//
// }
// }
//
// /**
// * 计算 height 和 y 值
// */
// if(t(top) && t(bottom)) { // top bottom 都有则直接拉伸或缩小
//
// that.y = top;
//
// that.height = pH_Z - top - bottom;
//
// } else {
// // 先设置下自己的 height
// t(percentHeight) && (tH_Z = that.height = pH_Z * percentHeight / 100);
//
// // 先考虑 horizonCenter 属性
// if(t(verticalCenter)) {
// // x 值 = 父节点的中间值 - 自己高度的一半 - 居中差值
// that.y = pH_Z / 2 - tH_Z / 2 + verticalCenter;
//
// } else if(t(top)) { // 假如有 top
//
// that.y = top;
//
// } else if(t(bottom)) { // 假如有 bottom
//
// that.y = pH_Z - bottom - tH_Z;
//
// }
// }
//
// // console.log(that.name, that.width, that.height);
// that.children.forEach(v => v.adjustProxy.adjustLayout());
// }
}
......@@ -3,7 +3,7 @@
*/
import {Event, EventDispatcher, MouseEvent} from "../../2d/events";
import {Event, EventDispatcher, MouseEvent} from "../../2d/events/index";
import {HashObject} from "../../2d/HashObject";
import {executeBehavior} from "../behavior-runtime";
import {injectProp} from "../utils";
......
......@@ -8,6 +8,7 @@ import {instantiate} from "./view-interpreter";
import {injectProperties, objClone} from "../utils/utils";
import {devicePixelRatio} from "../../2d/const";
import {Point} from "../../2d/math/Point";
import {alignMgr} from "../decorators/AlignManager";
const propPrefixFilter = ['_', '__', '$'];
const includeProps = ['_width', '_height', 'worldMatrix'];
......@@ -39,11 +40,15 @@ export class EditorStage extends Node {
this.name = 'editor-stage';
stage.width = stage.viewRect.width;
stage.height = stage.viewRect.height;
this.percentWidth = 100;
this.percentHeight = 100;
}
launch(onStart) {
Stage.addUpdateObj(alignMgr);
onStart();
}
......@@ -124,7 +129,7 @@ export class EditorStage extends Node {
//console.log('modifyProps:', key, offsetV, node[key]);
}
}
node.adjustProxy.adjustLayout();
//node.adjustProxy.adjustLayout();
return true;
} else {
console.warn('node not found:', nodePath);
......
......@@ -2,21 +2,24 @@
* Created by rockyl on 2019-11-05.
*/
import {Stage} from "../../2d/display/index";
import {StackContainer} from "./StackContainer";
import {loadAssets} from "./assets-manager";
import {instantiate} from "./view-interpreter";
import {dataCenter, DataCenter} from "./data-center";
import {setProcessMetaLibs} from "../behavior-runtime/index";
import {Tween} from "../../2d/tween/index";
import {Rect} from "./nodes/index";
import {injectEnv} from "./enviroment";
import {Toast} from "./Toast";
import {arrayFind} from "../utils/index";
import {Node} from "./nodes/Node";
import {bind, createStore} from "./mvvm/index";
import {registerCustomModules} from "./custom-module";
import {dealPageRemainTime, dealPxEnv} from "../px-logics";
import { Stage } from "../../2d/display/index";
import { StackContainer } from "./StackContainer";
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";
import { Tween } from "../../2d/tween/index";
import { Rect } from "./nodes/index";
import { injectEnv } from "./enviroment";
import { Toast } from "./Toast";
import { arrayFind } from "../utils/index";
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";
import { alignMgr } from "../decorators/AlignManager";
/**
* 游戏舞台
......@@ -24,6 +27,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 +50,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,35 +106,33 @@ 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;
/// TODO 我也不知道为什么,在 Tween 前加入 flush 可以解决因使用 Tween 移动而产生的相对定位节点大小或位置抖动剧烈的问题
Stage.addUpdateObj(alignMgr);
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();
......@@ -135,61 +141,98 @@ 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);
if (sceneEntry) {
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) {
if(cache) {
view = this._viewCache[name];
}
if (!view) {
if(!view) {
let viewConfig = this.getViewConfigByName(name);
if (viewConfig) {
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 = {};
if (viewConfig.store) {
if(viewConfig.store) {
const {exp, computed} = viewConfig.store;
store = createStore(exp, computed);
}
......@@ -197,14 +240,11 @@ 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');
if (cache) {
if(cache) {
this._viewCache[name] = view;
}
} else {
......@@ -222,28 +262,98 @@ export class GameStage extends Node {
return arrayFind(this._config.views, view => view.name === name);
}
/**
* 设置半透明层是否可见
* @param visible
*/
setBlackLayerVisible(visible) {
this._blackLayer.visible = visible;
}
onPopupContainerStart(e) {
const {action, view, lastView, options, hasView} = e.data;
const target = <StackContainer>e.target;
onPopupContainerChange(e) {
const {action, view, options} = e.data;
switch (action) {
switch(action) {
case 'push':
case 'replace':
case 'popAll':
if (options && options.center) {
view.horizonCenter = 0;
view.verticalCenter = 0;
if(options && options.center) {
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();
}
)
})
}
}
......@@ -23,23 +23,24 @@ export class Toast extends Node {
this.verticalCenter = 0;
}
show(props: any = {}) {
async show(props: any = {}) {
if (!props.text) {
return;
}
let contentView = this.getContent(props.viewName);
let contentView = await this.getContent(props.viewName, props);
let lab = contentView.getChildByName('lab');
if (!lab) {
console.warn('[lab] child no exists on toast view');
return;
}
const {text, padding = 10, duration = 1000, showDuration = 300, hideDuration = 200} = props;
const {text, padding = 10, paddingH, paddingV, duration = 1000, showDuration = 300, hideDuration = 200} = props;
lab.text = text;
lab.x = lab.y = padding;
this.width = contentView.width = lab.width + padding * 2;
this.height = contentView.height = lab.height + padding * 2;
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;
......@@ -55,11 +56,11 @@ export class Toast extends Node {
hide(animation = true, hideDuration = 200) {
if (this._content) {
const contentView = this._content;
if(animation){
if (animation) {
Tween.get(contentView, null, null, true)
.to({alpha: 0}, hideDuration)
.call(this.removeContentView, this)
}else{
} else {
Tween.removeTweens(contentView);
this.removeContentView();
}
......@@ -72,27 +73,29 @@ export class Toast extends Node {
this._content = null;
}
private getContent(viewName) {
private async getContent(viewName, props) {
let view;
if (this.children.length == 0) {
if (viewName) {
view = this._gameStage.instantiateView(viewName);
view = await this._gameStage.instantiateView(viewName);
}
if (!view) {
if (!this._contentSample) {
const {borderRadius = 10, labColor = 'white', labSize = 30, bgColor = 'black', bgAlpha = 0.7} = props;
this._contentSample = new Node();
let bg = new Rect();
bg.borderRadius = 10;
bg.borderRadius = borderRadius;
bg.percentWidth = 100;
bg.percentHeight = 100;
bg.fillColor = 'black';
bg.alpha = 0.7;
bg.fillColor = bgColor;
bg.alpha = bgAlpha;
this._contentSample.addChild(bg);
let lab = new Label();
lab.name = 'lab';
lab.fillColor = 'white';
lab.size = 30;
lab.fillColor = labColor;
lab.size = labSize;
this._contentSample.addChild(lab);
}
view = this._contentSample;
......
......@@ -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();
......
......@@ -66,7 +66,9 @@ export class Rect extends ShapeBase {
protected redraw() {
const {width, height, borderRadius,} = this;
if(width == 0 || height == 0){
return;
}
if (borderRadius > 0) {
this.drawRoundedRect(0, 0, width, height, borderRadius);
} else {
......@@ -83,6 +85,9 @@ export class Circle extends ShapeBase {
super.redraw();
const {width, height} = this;
if(width == 0 || height == 0){
return;
}
const radius = Math.min(width, height) / 2;
this.drawCircle(radius, radius, radius);
......
/**
* 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();
}
}
},
};
......@@ -3,18 +3,21 @@
*/
import {Stage} from "../2d/display/index";
import {registerCustomModuleFromConfig, registerScripts, RENDERER_TYPE, setProcessMetaLibs, StageScaleMode} from "..";
import {GameStage} from "./game-warpper/index";
import {setGlobalContext} from "./behavior-runtime";
import {GameStage, registerCustomModuleFromConfig} from "./game-warpper/index";
import {setGlobalContext, setProcessMetaLibs} from "./behavior-runtime/index";
import {globalLoader} from "../2d/loader/Loader";
import {Event} from "../2d/events/Event";
import builtinLoadingView from "./game-warpper/LoadingView";
import {queryParams} from "./web";
import {initAutoLayout} from "./game-warpper/auto-layout";
import {registerScripts} from "./decorators/scripts";
import {RENDERER_TYPE, StageScaleMode} from "../2d/const";
import { alignMgr } from "./decorators/AlignManager";
import {EditorStage} from "./game-warpper/EditorStage";
export let gameStage: GameStage;
export let editorStage: EditorStage;
export let alignManager = alignMgr;
export let editorMode = false;
export let assetResolver;
......
......@@ -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);
......
......@@ -31,23 +31,23 @@ export function arrayFind(arr, predicate) {
* @param obj
*/
export function objClone(obj) {
return obj ? JSON.parse(JSON.stringify(obj)) : obj;
return obj ? JSON.parse(JSON.stringify(obj)) : obj;
}
const percentKeys = ['width', 'height'];
const percentKeys = ['width', 'height', 'top', 'left', 'bottom', 'right'];
export function propertyParse(key, node, properties) {
let value = properties[key];
let targetKey = key;
if (percentKeys.indexOf(key) >= 0) {
if (typeof value === 'string') {
if (value[value.length - 1] === '%') {
targetKey = 'percent' + key[0].toUpperCase() + key.substr(1);
}
value = parseInt(value);
}
}
node[targetKey] = value;
let value = properties[key];
let targetKey = key;
if(percentKeys.indexOf(key) >= 0) {
if(typeof value === 'string') {
if(value[value.length - 1] === '%') {
targetKey = 'percent' + key[0].toUpperCase() + key.substr(1);
}
value = parseInt(value);
}
}
node[targetKey] = value;
}
/**
......@@ -57,15 +57,15 @@ export function propertyParse(key, node, properties) {
* @param throwException
*/
export function getDataByPath(scope, path, throwException?) {
let func = new Function('scope', `return scope` + (path ? ('.' + path) : ''));
try {
return func(scope);
} catch (e) {
//console.warn(e);
if (throwException) {
throw e;
}
}
let func = new Function('scope', `return scope` + (path ? ('.' + path) : ''));
try {
return func(scope);
} catch(e) {
//console.warn(e);
if(throwException) {
throw e;
}
}
}
/**
......@@ -74,14 +74,14 @@ export function getDataByPath(scope, path, throwException?) {
* @param throwException
*/
export function safeEval(code, throwException = false) {
let func = new Function(code);
try {
return func();
} catch (e) {
if (throwException) {
throw e;
}
}
let func = new Function(code);
try {
return func();
} catch(e) {
if(throwException) {
throw e;
}
}
}
/**
......@@ -328,11 +328,11 @@ export const cmdOldPrefix = '//z-';
* @param source
*/
export function injectProperties(target, source) {
for (let key in source) {
if (key.indexOf('//') !== 0 && !source.hasOwnProperty(cmdPrefix + key)) {
propertyParse(key, target, source);
}
}
for(let key in source) {
if(key.indexOf('//') !== 0 && !source.hasOwnProperty(cmdPrefix + key)) {
propertyParse(key, target, source);
}
}
return target;
}
......@@ -344,14 +344,25 @@ export function injectProperties(target, source) {
* @param includeSelf
*/
export function traverseViewNode(node: Container, callback: Function, includeSelf = false) {
if (includeSelf) {
callback(node);
}
for (let child of node.children) {
callback(child, node);
if(includeSelf) {
callback(node);
}
for(let child of node.children) {
callback(child, node);
if (child.children && child.children.length > 0) {
traverseViewNode(child, callback);
}
}
}
/**
* 数字转化为boolean值
* NaN -> false 'aaa' -> false null -> false undefined -> false
* 666 -> true '007' -> true Infinity -> true
* @param v
* @returns {boolean}
*/
export function toBoolean(v): boolean {
return !isNaN(v) && v !== null && v !== undefined;
}
......@@ -438,10 +438,10 @@ rollup-plugin-node-resolve@^5.2.0:
resolve "^1.11.1"
rollup-pluginutils "^2.8.1"
rollup-plugin-progress@^1.1.1:
version "1.1.1"
resolved "https://registry.npm.taobao.org/rollup-plugin-progress/download/rollup-plugin-progress-1.1.1.tgz#fcce2f915d545014ac89ea0927ee97cb48052f60"
integrity sha1-/M4vkV1UUBSsieoJJ+6Xy0gFL2A=
rollup-plugin-progress@^1.1.2:
version "1.1.2"
resolved "https://registry.npm.taobao.org/rollup-plugin-progress/download/rollup-plugin-progress-1.1.2.tgz#5c1dfe7c50f654906bc34d167d5512ee1a4b72d5"
integrity sha1-XB3+fFD2VJBrw00WfVUS7hpLctU=
dependencies:
chalk "^2.4.2"
......
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