Formatting

This commit is contained in:
Mario Zechner 2023-09-04 10:56:28 +02:00
parent 603ef985da
commit 600e43de24
4 changed files with 541 additions and 542 deletions

View File

@ -50,7 +50,7 @@ import {
} from "@esotericsoftware/spine-core";
class BaseSpineGameObject extends Phaser.GameObjects.GameObject {
constructor(scene: Phaser.Scene, type: string) {
constructor (scene: Phaser.Scene, type: string) {
super(scene, type);
}
}
@ -58,7 +58,7 @@ class BaseSpineGameObject extends Phaser.GameObjects.GameObject {
/** A bounds provider calculates the bounding box for a skeleton, which is then assigned as the size of the SpineGameObject. */
export interface SpineGameObjectBoundsProvider {
// Returns the bounding box for the skeleton, in skeleton space.
calculateBounds(gameObject: SpineGameObject): {
calculateBounds (gameObject: SpineGameObject): {
x: number;
y: number;
width: number;
@ -68,7 +68,7 @@ export interface SpineGameObjectBoundsProvider {
/** A bounds provider that calculates the bounding box from the setup pose. */
export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider {
calculateBounds(gameObject: SpineGameObject) {
calculateBounds (gameObject: SpineGameObject) {
if (!gameObject.skeleton) return { x: 0, y: 0, width: 0, height: 0 };
// Make a copy of animation state and skeleton as this might be called while
// the skeleton in the GameObject has already been heavily modified. We can not
@ -85,20 +85,19 @@ export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider {
/** A bounds provider that calculates the bounding box by taking the maximumg bounding box for a combination of skins and specific animation. */
export class SkinsAndAnimationBoundsProvider
implements SpineGameObjectBoundsProvider
{
implements SpineGameObjectBoundsProvider {
/**
* @param animation The animation to use for calculating the bounds. If null, the setup pose is used.
* @param skins The skins to use for calculating the bounds. If empty, the default skin is used.
* @param timeStep The time step to use for calculating the bounds. A smaller time step means more precision, but slower calculation.
*/
constructor(
constructor (
private animation: string | null,
private skins: string[] = [],
private timeStep: number = 0.05
) {}
) { }
calculateBounds(gameObject: SpineGameObject): {
calculateBounds (gameObject: SpineGameObject): {
x: number;
y: number;
width: number;
@ -199,11 +198,11 @@ export class SpineGameObject extends DepthMixin(
skeleton: Skeleton;
animationStateData: AnimationStateData;
animationState: AnimationState;
beforeUpdateWorldTransforms: (object: SpineGameObject) => void = () => {};
afterUpdateWorldTransforms: (object: SpineGameObject) => void = () => {};
beforeUpdateWorldTransforms: (object: SpineGameObject) => void = () => { };
afterUpdateWorldTransforms: (object: SpineGameObject) => void = () => { };
private premultipliedAlpha = false;
constructor(
constructor (
scene: Phaser.Scene,
private plugin: SpinePlugin,
x: number,
@ -223,7 +222,7 @@ export class SpineGameObject extends DepthMixin(
this.updateSize();
}
updateSize() {
updateSize () {
if (!this.skeleton) return;
let bounds = this.boundsProvider.calculateBounds(this);
// For some reason the TS compiler and the ComputedSize mixin don't work well together and we have
@ -236,7 +235,7 @@ export class SpineGameObject extends DepthMixin(
}
/** Converts a point from the skeleton coordinate system to the Phaser world coordinate system. */
skeletonToPhaserWorldCoordinates(point: { x: number; y: number }) {
skeletonToPhaserWorldCoordinates (point: { x: number; y: number }) {
let transform = this.getWorldTransformMatrix();
let a = transform.a,
b = transform.b,
@ -251,7 +250,7 @@ export class SpineGameObject extends DepthMixin(
}
/** Converts a point from the Phaser world coordinate system to the skeleton coordinate system. */
phaserWorldCoordinatesToSkeleton(point: { x: number; y: number }) {
phaserWorldCoordinatesToSkeleton (point: { x: number; y: number }) {
let transform = this.getWorldTransformMatrix();
transform = transform.invert();
let a = transform.a,
@ -267,7 +266,7 @@ export class SpineGameObject extends DepthMixin(
}
/** Converts a point from the Phaser world coordinate system to the bone's local coordinate system. */
phaserWorldCoordinatesToBone(point: { x: number; y: number }, bone: Bone) {
phaserWorldCoordinatesToBone (point: { x: number; y: number }, bone: Bone) {
this.phaserWorldCoordinatesToSkeleton(point);
if (bone.parent) {
bone.parent.worldToLocal(point as Vector2);
@ -280,7 +279,7 @@ export class SpineGameObject extends DepthMixin(
* Updates the {@link AnimationState}, applies it to the {@link Skeleton}, then updates the world transforms of all bones.
* @param delta The time delta in milliseconds
*/
updatePose(delta: number) {
updatePose (delta: number) {
this.animationState.update(delta / 1000);
this.animationState.apply(this.skeleton);
this.beforeUpdateWorldTransforms(this);
@ -288,16 +287,16 @@ export class SpineGameObject extends DepthMixin(
this.afterUpdateWorldTransforms(this);
}
preUpdate(time: number, delta: number) {
preUpdate (time: number, delta: number) {
if (!this.skeleton || !this.animationState) return;
this.updatePose(delta);
}
preDestroy() {
preDestroy () {
// FIXME tear down any event emitters
}
willRender(camera: Phaser.Cameras.Scene2D.Camera) {
willRender (camera: Phaser.Cameras.Scene2D.Camera) {
if (!this.visible) return false;
var GameObjectRenderMask = 0xf;
@ -315,7 +314,7 @@ export class SpineGameObject extends DepthMixin(
return result;
}
renderWebGL(
renderWebGL (
renderer: Phaser.Renderer.WebGL.WebGLRenderer,
src: SpineGameObject,
camera: Phaser.Cameras.Scene2D.Camera,
@ -363,7 +362,7 @@ export class SpineGameObject extends DepthMixin(
}
}
renderCanvas(
renderCanvas (
renderer: Phaser.Renderer.Canvas.CanvasRenderer,
src: SpineGameObject,
camera: Phaser.Cameras.Scene2D.Camera,

View File

@ -52,7 +52,7 @@ export type SkeletonMeshMaterialParametersCustomizer = (
) => void;
export class SkeletonMeshMaterial extends THREE.ShaderMaterial {
constructor(customizer: SkeletonMeshMaterialParametersCustomizer) {
constructor (customizer: SkeletonMeshMaterialParametersCustomizer) {
let vertexShader = `
attribute vec4 color;
varying vec2 vUv;
@ -118,11 +118,11 @@ export class SkeletonMesh extends THREE.Object3D {
private vertices = Utils.newFloatArray(1024);
private tempColor = new Color();
constructor(
constructor (
skeletonData: SkeletonData,
private materialCustomerizer: SkeletonMeshMaterialParametersCustomizer = (
material
) => {}
) => { }
) {
super();
@ -131,7 +131,7 @@ export class SkeletonMesh extends THREE.Object3D {
this.state = new AnimationState(animData);
}
update(deltaTime: number) {
update (deltaTime: number) {
let state = this.state;
let skeleton = this.skeleton;
@ -142,13 +142,13 @@ export class SkeletonMesh extends THREE.Object3D {
this.updateGeometry();
}
dispose() {
dispose () {
for (var i = 0; i < this.batches.length; i++) {
this.batches[i].dispose();
}
}
private clearBatches() {
private clearBatches () {
for (var i = 0; i < this.batches.length; i++) {
this.batches[i].clear();
this.batches[i].visible = false;
@ -156,7 +156,7 @@ export class SkeletonMesh extends THREE.Object3D {
this.nextBatchIndex = 0;
}
private nextBatch() {
private nextBatch () {
if (this.batches.length == this.nextBatchIndex) {
let batch = new MeshBatcher(10920, this.materialCustomerizer);
this.add(batch);
@ -167,7 +167,7 @@ export class SkeletonMesh extends THREE.Object3D {
return batch;
}
private updateGeometry() {
private updateGeometry () {
this.clearBatches();
let tempPos = this.tempPos;

View File

@ -170,7 +170,7 @@ export class SkeletonRenderer {
WebGLBlendModeConverter.getSourceColorGLBlendMode(blendMode, premultipliedAlpha),
WebGLBlendModeConverter.getSourceAlphaGLBlendMode(blendMode, premultipliedAlpha),
WebGLBlendModeConverter.getDestColorGLBlendMode(blendMode),
WebGLBlendModeConverter.getDestAlphaGLBlendMode(blendMode, premultipliedAlpha) );
WebGLBlendModeConverter.getDestAlphaGLBlendMode(blendMode, premultipliedAlpha));
}
if (clipper.isClipping()) {