reformat code

This commit is contained in:
yhh
2020-07-28 16:25:20 +08:00
parent 5994f0bee3
commit 514572f291
103 changed files with 2896 additions and 2839 deletions

View File

@@ -64,8 +64,8 @@ module es {
"gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" +
"}";
constructor(){
super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag,{
constructor() {
super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag, {
screenWidth: Core.graphicsDevice.viewport.width,
screenHeight: Core.graphicsDevice.viewport.height
});

View File

@@ -29,7 +29,7 @@ module es {
"gl_FragColor = c;\n" +
"}";
constructor(){
constructor() {
super(PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc);
}
}

View File

@@ -1,11 +1,11 @@
module es {
export class GraphicsCapabilities extends egret.Capabilities {
public initialize(device: GraphicsDevice){
public initialize(device: GraphicsDevice) {
this.platformInitialize(device);
}
private platformInitialize(device: GraphicsDevice){
private platformInitialize(device: GraphicsDevice) {
if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
return;
let capabilities = this;
@@ -13,14 +13,14 @@ module es {
let systemInfo = wx.getSystemInfoSync();
let systemStr = systemInfo.system.toLowerCase();
if (systemStr.indexOf("ios") > -1){
if (systemStr.indexOf("ios") > -1) {
capabilities["os"] = "iOS";
} else if(systemStr.indexOf("android") > -1){
} else if (systemStr.indexOf("android") > -1) {
capabilities["os"] = "Android";
}
let language = systemInfo.language;
if (language.indexOf('zh') > -1){
if (language.indexOf('zh') > -1) {
language = "zh-CN";
} else {
language = "en-US";

View File

@@ -1,19 +1,20 @@
module es {
export class GraphicsDevice {
private _viewport: Viewport;
public get viewport(): Viewport{
return this._viewport;
}
public graphicsCapabilities: GraphicsCapabilities;
constructor(){
constructor() {
this.setup();
this.graphicsCapabilities = new GraphicsCapabilities();
this.graphicsCapabilities.initialize(this);
}
private setup(){
private _viewport: Viewport;
public get viewport(): Viewport {
return this._viewport;
}
private setup() {
this._viewport = new Viewport(0, 0, Core._instance.stage.stageWidth, Core._instance.stage.stageHeight);
}
}

View File

@@ -1,10 +1,5 @@
module es {
export class PostProcessor {
public enabled: boolean;
public effect: egret.Filter;
public scene: Scene;
public shape: egret.Shape;
public static default_vert = "attribute vec2 aVertexPosition;\n" +
"attribute vec2 aTextureCoord;\n" +
"attribute vec2 aColor;\n" +
@@ -22,13 +17,17 @@ module es {
"vTextureCoord = aTextureCoord;\n" +
"vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" +
"}";
public enabled: boolean;
public effect: egret.Filter;
public scene: Scene;
public shape: egret.Shape;
constructor(effect: egret.Filter = null){
constructor(effect: egret.Filter = null) {
this.enabled = true;
this.effect = effect;
}
public onAddedToScene(scene: Scene){
public onAddedToScene(scene: Scene) {
this.scene = scene;
this.shape = new egret.Shape();
this.shape.graphics.beginFill(0xFFFFFF, 1);
@@ -37,24 +36,25 @@ module es {
scene.addChild(this.shape);
}
public process(){
public process() {
this.drawFullscreenQuad();
}
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
protected drawFullscreenQuad(){
this.scene.filters = [this.effect];
// this.shape.filters = [this.effect];
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number) {
}
public unload(){
if (this.effect){
public unload() {
if (this.effect) {
this.effect = null;
}
this.scene.removeChild(this.shape);
this.scene = null;
}
protected drawFullscreenQuad() {
this.scene.filters = [this.effect];
// this.shape.filters = [this.effect];
}
}
}

View File

@@ -1,6 +1,6 @@
module es {
export class GaussianBlurPostProcessor extends PostProcessor {
public onAddedToScene(scene: Scene){
public onAddedToScene(scene: Scene) {
super.onAddedToScene(scene);
this.effect = new GaussianBlurEffect();
}

View File

@@ -1,7 +1,7 @@
///<reference path="./Renderer.ts" />
module es {
export class DefaultRenderer extends Renderer {
constructor(){
constructor() {
super(0, null);
}
@@ -9,7 +9,7 @@ module es {
let cam = this.camera ? this.camera : scene.camera;
this.beginRender(cam);
for (let i = 0; i < scene.renderableComponents.count; i++){
for (let i = 0; i < scene.renderableComponents.count; i++) {
let renderable = scene.renderableComponents.buffer[i];
if (renderable.enabled && renderable.isVisibleFromCamera(cam))
this.renderAfterStateCheck(renderable, cam);

View File

@@ -40,7 +40,7 @@ module es {
* 用于排序IRenderables的比较器
*/
export class RenderableComparer {
public compare(self: IRenderable, other: IRenderable){
public compare(self: IRenderable, other: IRenderable) {
return other.renderLayer - self.renderLayer;
}
}

View File

@@ -1,18 +1,10 @@
module es {
export class PolyLight extends RenderableComponent {
public power: number;
protected _radius: number;
private _lightEffect;
private _indices: number[] = [];
public get radius(){
return this._radius;
}
public set radius(value: number){
this.setRadius(value);
}
constructor(radius: number, color: number, power: number){
constructor(radius: number, color: number, power: number) {
super();
this.radius = radius;
@@ -21,18 +13,18 @@ module es {
this.computeTriangleIndices();
}
private computeTriangleIndices(totalTris: number = 20){
this._indices.length = 0;
protected _radius: number;
for (let i = 0; i < totalTris; i += 2){
this._indices.push(0);
this._indices.push(i + 2);
this._indices.push(i + 1);
}
public get radius() {
return this._radius;
}
public setRadius(radius: number){
if (radius != this._radius){
public set radius(value: number) {
this.setRadius(value);
}
public setRadius(radius: number) {
if (radius != this._radius) {
this._radius = radius;
this._areBoundsDirty = true;
}
@@ -41,8 +33,18 @@ module es {
public render(camera: Camera) {
}
public reset(){
public reset() {
}
private computeTriangleIndices(totalTris: number = 20) {
this._indices.length = 0;
for (let i = 0; i < totalTris; i += 2) {
this._indices.push(0);
this._indices.push(i + 2);
this._indices.push(i + 1);
}
}
}
}

View File

@@ -14,7 +14,7 @@ module es {
*/
public readonly renderOrder: number = 0;
protected constructor(renderOrder: number, camera: Camera = null){
protected constructor(renderOrder: number, camera: Camera = null) {
this.camera = camera;
this.renderOrder = renderOrder;
}
@@ -23,41 +23,44 @@ module es {
* 当渲染器被添加到场景时调用
* @param scene
*/
public onAddedToScene(scene: Scene){}
public onAddedToScene(scene: Scene) {
}
/**
* 当场景结束或渲染器从场景中移除时调用。使用这个进行清理。
*/
public unload(){ }
/**
*
* @param cam
*/
protected beginRender(cam: Camera){ }
public unload() {
}
public abstract render(scene: Scene);
/**
*
* @param renderable
* @param cam
*/
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera){
renderable.render(cam);
}
/**
* 当默认场景渲染目标被调整大小和当场景已经开始添加渲染器时调用
* @param newWidth
* @param newHeight
*/
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number) {
}
public compareTo(other: Renderer): number{
public compareTo(other: Renderer): number {
return this.renderOrder - other.renderOrder;
}
/**
*
* @param cam
*/
protected beginRender(cam: Camera) {
}
/**
*
* @param renderable
* @param cam
*/
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera) {
renderable.render(cam);
}
}
}

View File

@@ -18,17 +18,17 @@ module es {
this._mask.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height);
this._mask.graphics.endFill();
egret.Tween.get(this).to({ _alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType)
egret.Tween.get(this).to({_alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType)
.call(async () => {
await this.loadNextScene();
}).wait(this.delayBeforeFadeInDuration).call(() => {
egret.Tween.get(this).to({ _alpha: 0 }, this.fadeOutDuration * 1000, this.fadeEaseType).call(() => {
egret.Tween.get(this).to({_alpha: 0}, this.fadeOutDuration * 1000, this.fadeEaseType).call(() => {
this.transitionComplete();
});
});
}
public render(){
public render() {
this._mask.graphics.clear();
this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
this._mask.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height);

View File

@@ -3,7 +3,6 @@ module es {
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
*/
export abstract class SceneTransition {
private _hasPreviousSceneRender: boolean;
/** 是否加载新场景的标志 */
public loadsNewScene: boolean;
/**
@@ -11,15 +10,22 @@ module es {
* 对于场景过渡isNewSceneLoaded应该在中点设置为true这就标识一个新的场景被加载了。
*/
public isNewSceneLoaded: boolean;
/** 返回新加载场景的函数 */
protected sceneLoadAction: Function;
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
public onScreenObscured: Function;
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
public onTransitionCompleted: Function;
/** 返回新加载场景的函数 */
protected sceneLoadAction: Function;
public get hasPreviousSceneRender(){
if (!this._hasPreviousSceneRender){
constructor(sceneLoadAction: Function) {
this.sceneLoadAction = sceneLoadAction;
this.loadsNewScene = sceneLoadAction != null;
}
private _hasPreviousSceneRender: boolean;
public get hasPreviousSceneRender() {
if (!this._hasPreviousSceneRender) {
this._hasPreviousSceneRender = true;
return false;
}
@@ -27,13 +33,9 @@ module es {
return true;
}
constructor(sceneLoadAction: Function) {
this.sceneLoadAction = sceneLoadAction;
this.loadsNewScene = sceneLoadAction != null;
public preRender() {
}
public preRender() { }
public render() {
}
@@ -43,6 +45,17 @@ module es {
this.transitionComplete();
}
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise<boolean> {
return new Promise((resolve) => {
let start = reverseDirection ? 1 : 0;
let end = reverseDirection ? 0 : 1;
egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(() => {
resolve();
});
});
}
protected transitionComplete() {
Core._instance._sceneTransition = null;
@@ -62,16 +75,5 @@ module es {
Core.scene = await this.sceneLoadAction();
this.isNewSceneLoaded = true;
}
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise<boolean>{
return new Promise((resolve)=>{
let start = reverseDirection ? 1 : 0;
let end = reverseDirection ? 0 : 1;
egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(()=>{
resolve();
});
});
}
}
}

View File

@@ -1,20 +1,14 @@
module es {
export class WindTransition extends SceneTransition {
public duration = 1;
public easeType = egret.Ease.quadOut;
private _mask: egret.Shape;
private _windEffect: egret.CustomFilter;
public duration = 1;
public set windSegments(value: number) {
this._windEffect.uniforms._windSegments = value;
}
public set size(value: number) {
this._windEffect.uniforms._size = value;
}
public easeType = egret.Ease.quadOut;
constructor(sceneLoadAction: Function) {
super(sceneLoadAction);
let vertexSrc = "attribute vec2 aVertexPosition;\n" +
let vertexSrc = "attribute vec2 aVertexPosition;\n" +
"attribute vec2 aTextureCoord;\n" +
"uniform vec2 projectionVector;\n" +
@@ -56,6 +50,14 @@ module es {
this._mask.filters = [this._windEffect];
}
public set windSegments(value: number) {
this._windEffect.uniforms._windSegments = value;
}
public set size(value: number) {
this._windEffect.uniforms._size = value;
}
public async onBeginTransition() {
this.loadNextScene();
await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType);

View File

@@ -2,42 +2,10 @@ module es {
export class Viewport {
private _x: number;
private _y: number;
private _width: number;
private _height: number;
private _minDepth: number;
private _maxDepth: number;
public get height(){
return this._height;
}
public set height(value: number){
this._height = value;
}
public get width(){
return this._width;
}
public set width(value: number){
this._width = value;
}
public get aspectRatio(){
if ((this._height != 0) && (this._width != 0))
return (this._width / this._height);
return 0;
}
public get bounds(){
return new Rectangle(this._x, this._y, this._width, this._height);
}
public set bounds(value: Rectangle){
this._x = value.x;
this._y = value.y;
this._width = value.width;
this._height = value.height;
}
constructor(x: number, y: number, width: number, height: number){
constructor(x: number, y: number, width: number, height: number) {
this._x = x;
this._y = y;
this._width = width;
@@ -46,5 +14,42 @@ module es {
this._maxDepth = 1;
}
private _width: number;
public get width() {
return this._width;
}
public set width(value: number) {
this._width = value;
}
private _height: number;
public get height() {
return this._height;
}
public set height(value: number) {
this._height = value;
}
public get aspectRatio() {
if ((this._height != 0) && (this._width != 0))
return (this._width / this._height);
return 0;
}
public get bounds() {
return new Rectangle(this._x, this._y, this._width, this._height);
}
public set bounds(value: Rectangle) {
this._x = value.x;
this._y = value.y;
this._width = value.width;
this._height = value.height;
}
}
}