Commit efdac5b1 authored by rockyl's avatar rockyl

修改CameraController方便UI适配

parent a22a4702
/**
* Created by rockyl on 2019-03-19.
*/
const glob = require('glob');
const fs = require('fs');
let files = glob.sync('src/**/!(index|registerAllComponents).ts');
let fileContent = `import {registerDef} from "scilla-core"
`;
const imports = [];
const contents = [];
for(let file of files){
let requirePath = '.' + file.replace('src', '').replace('.ts', '');
let fullClassName = file.replace('src', 'components').replace('.ts', '');
let shortClassName = fullClassName.substr(fullClassName.lastIndexOf('/') + 1);
imports.push(`import ${shortClassName} from '${requirePath}';`);
contents.push(` registerDef('${fullClassName}', ${shortClassName});`);
}
fileContent += imports.join('\n') + `
export function registerAllComponents(){
` + contents.join('\n') + '\n}';
fs.writeFileSync('src/registerAllComponents.ts', fileContent);
\ No newline at end of file
{
"name": "scilla-components",
"version": "1.0.0",
"main": "./dist/bundle.js",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"license": "MIT",
"scripts": {
......@@ -11,6 +11,7 @@
"tslib": "^1.9.3"
},
"devDependencies": {
"glob": "^7.1.3",
"rollup": "^0.66.6",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^3.4.0",
......
......@@ -25,6 +25,6 @@ export default {
useTsconfigDeclarationDir: true,
}),
commonjs(),
uglify({}),
//uglify({}),
]
};
......@@ -7,3 +7,5 @@ export * from './base';
export * from './other';
export * from './renderer';
export * from './ui';
export * from './registerAllComponents'
......@@ -10,8 +10,8 @@ import Transform from "../base/Transform";
* 相机控制组件
*/
export default class CameraController extends ScillaComponent {
target: Entity;
viewportAnchor: Vector2D = createVector2D(0.5, 0.5);
target: Entity;
maxScale = 1.2;
private targetPosition: Vector2D;
......@@ -25,7 +25,7 @@ export default class CameraController extends ScillaComponent {
onAwake() {
super.onAwake();
const {target, viewportAnchor} = this;
const {target,} = this;
this.stageSize = getStageSize();
......@@ -34,16 +34,26 @@ export default class CameraController extends ScillaComponent {
}
this.followPosition = createVector2D();
if (viewportAnchor) {
this.updateViewport();
}
onUpdate(t) {
super.onUpdate(t);
this.followTarget();
}
updateViewport() {
if (this.viewportAnchor) {
const {width, height} = this.stageSize;
const {x, y} = this.viewportAnchor;
this.transform.position.setXY(width * x, height * y);
this.transform.width = width;
this.transform.height = height;
}
}
onUpdate(t) {
super.onUpdate(t);
followTarget() {
if (!this.targetPosition) {
return;
}
......@@ -57,12 +67,4 @@ export default class CameraController extends ScillaComponent {
position.copyFrom(math.lerpObj(position, this.followPosition, 0.1, Vector2D, ['x', 'y']));
}
onSleep() {
super.onSleep();
}
onDestroy() {
super.onDestroy();
}
}
import {registerDef} from "scilla"
import BounceZoom from './animation/BounceZoom';
import Fade from './animation/Fade';
import Rotation from './animation/Rotation';
import RoundLoop from './animation/RoundLoop';
import Swing from './animation/Swing';
import TouchZoom from './animation/TouchZoom';
import Wave from './animation/Wave';
import ZoomLoop from './animation/ZoomLoop';
import InteractComponent from './base/InteractComponent';
import TouchInterrupt from './base/TouchInterrupt';
import Transform from './base/Transform';
import CameraController from './other/CameraController';
import ContentSizeFitter from './other/ContentSizeFitter';
import RelativeLayout from './other/RelativeLayout';
import CircleRenderer from './renderer/CircleRenderer';
import FrameAnimationRenderer from './renderer/FrameAnimationRenderer';
import GraphicRenderer from './renderer/GraphicRenderer';
import LineRenderer from './renderer/LineRenderer';
import RectRenderer from './renderer/RectRenderer';
import Renderer from './renderer/Renderer';
import TextRenderer from './renderer/TextRenderer';
import TextureRenderer from './renderer/TextureRenderer';
import Button from './ui/Button';
import ProgressBar from './ui/ProgressBar';
import ScrollView from './ui/ScrollView';
export function registerAllComponents(){
registerDef('components/animation/BounceZoom', BounceZoom);
registerDef('components/animation/Fade', Fade);
registerDef('components/animation/Rotation', Rotation);
registerDef('components/animation/RoundLoop', RoundLoop);
registerDef('components/animation/Swing', Swing);
registerDef('components/animation/TouchZoom', TouchZoom);
registerDef('components/animation/Wave', Wave);
registerDef('components/animation/ZoomLoop', ZoomLoop);
registerDef('components/base/InteractComponent', InteractComponent);
registerDef('components/base/TouchInterrupt', TouchInterrupt);
registerDef('components/base/Transform', Transform);
registerDef('components/other/CameraController', CameraController);
registerDef('components/other/ContentSizeFitter', ContentSizeFitter);
registerDef('components/other/RelativeLayout', RelativeLayout);
registerDef('components/renderer/CircleRenderer', CircleRenderer);
registerDef('components/renderer/FrameAnimationRenderer', FrameAnimationRenderer);
registerDef('components/renderer/GraphicRenderer', GraphicRenderer);
registerDef('components/renderer/LineRenderer', LineRenderer);
registerDef('components/renderer/RectRenderer', RectRenderer);
registerDef('components/renderer/Renderer', Renderer);
registerDef('components/renderer/TextRenderer', TextRenderer);
registerDef('components/renderer/TextureRenderer', TextureRenderer);
registerDef('components/ui/Button', Button);
registerDef('components/ui/ProgressBar', ProgressBar);
registerDef('components/ui/ScrollView', ScrollView);
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
*/
import Renderer from "./Renderer";
import {color} from 'scilla';
import {color} from "scilla";
/**
* 图形渲染组件
......
......@@ -3,7 +3,7 @@
*/
import GraphicRenderer from "./GraphicRenderer";
import {decorators} from 'scilla'
import {decorators} from "scilla"
const {dirtyFieldDetector} = decorators;
......
{
"compilerOptions": {
"target": "es5",
"outDir": "dist",
"experimentalDecorators": true,
"sourceMap": true,
"declarationDir": "./types",
"declarationDir": "types",
"declaration": true,
"lib": [
"es5",
......@@ -13,11 +14,10 @@
],
"baseUrl": "./",
"paths": {
"scilla": ["node_modules/scilla/src"]
"scilla": ["node_modules/scilla-core/src"]
}
},
"include": [
"src",
"libs"
"src"
]
}
\ No newline at end of file
......@@ -52,6 +52,19 @@ array-unique@^0.2.1:
resolved "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53"
integrity sha1-odl8yvy8JiXMcPrc6zalDFiwGlM=
balanced-match@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/balanced-match/download/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
brace-expansion@^1.1.7:
version "1.1.11"
resolved "http://registry.npm.taobao.org/brace-expansion/download/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
integrity sha1-PH/L9SnYcibz0vUrlm/1Jx60Qd0=
dependencies:
balanced-match "^1.0.0"
concat-map "0.0.1"
braces@^1.8.2:
version "1.8.5"
resolved "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz#ba77962e12dff969d6b76711e914b737857bf6a7"
......@@ -92,6 +105,11 @@ commander@~2.17.1:
resolved "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
integrity sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==
concat-map@0.0.1:
version "0.0.1"
resolved "http://registry.npm.taobao.org/concat-map/download/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
......@@ -170,6 +188,11 @@ fs-extra@7.0.0:
jsonfile "^4.0.0"
universalify "^0.1.0"
fs.realpath@^1.0.0:
version "1.0.0"
resolved "http://registry.npm.taobao.org/fs.realpath/download/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
glob-base@^0.3.0:
version "0.3.0"
resolved "https://registry.npmjs.org/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4"
......@@ -185,6 +208,18 @@ glob-parent@^2.0.0:
dependencies:
is-glob "^2.0.0"
glob@^7.1.3:
version "7.1.3"
resolved "http://registry.npm.taobao.org/glob/download/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1"
integrity sha1-OWCDLT8VdBCDQtr9OmezMsCWnfE=
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"
graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.15"
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
......@@ -195,7 +230,15 @@ has-flag@^3.0.0:
resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
inherits@~2.0.3:
inflight@^1.0.4:
version "1.0.6"
resolved "http://registry.npm.taobao.org/inflight/download/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=
dependencies:
once "^1.3.0"
wrappy "1"
inherits@2, inherits@~2.0.3:
version "2.0.3"
resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
......@@ -342,6 +385,13 @@ micromatch@^2.3.11:
parse-glob "^3.0.4"
regex-cache "^0.4.2"
minimatch@^3.0.4:
version "3.0.4"
resolved "http://registry.npm.taobao.org/minimatch/download/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
integrity sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=
dependencies:
brace-expansion "^1.1.7"
normalize-path@^2.0.1:
version "2.1.1"
resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9"
......@@ -357,6 +407,13 @@ object.omit@^2.0.0:
for-own "^0.1.4"
is-extendable "^0.1.1"
once@^1.3.0:
version "1.4.0"
resolved "http://registry.npm.taobao.org/once/download/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
dependencies:
wrappy "1"
parse-glob@^3.0.4:
version "3.0.4"
resolved "https://registry.npmjs.org/parse-glob/-/parse-glob-3.0.4.tgz#b2c376cfb11f35513badd173ef0bb6e3a388391c"
......@@ -367,6 +424,11 @@ parse-glob@^3.0.4:
is-extglob "^1.0.0"
is-glob "^2.0.0"
path-is-absolute@^1.0.0:
version "1.0.1"
resolved "http://registry.npm.taobao.org/path-is-absolute/download/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
path-parse@^1.0.5, path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
......@@ -556,3 +618,8 @@ util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
wrappy@1:
version "1.0.2"
resolved "http://registry.npm.taobao.org/wrappy/download/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
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