show body parts previews
This commit is contained in:
@@ -9,6 +9,15 @@ export enum CustomWokaBodyPart {
|
||||
Accessory = "Accessory",
|
||||
}
|
||||
|
||||
export enum CustomWokaBodyPartOrder {
|
||||
Body = 0,
|
||||
Eyes = 1,
|
||||
Hair = 2,
|
||||
Clothes = 3,
|
||||
Hat = 4,
|
||||
Accessory = 5,
|
||||
}
|
||||
|
||||
export interface CustomWokaPreviewerConfig {
|
||||
color: number;
|
||||
borderThickness: number;
|
||||
@@ -33,20 +42,22 @@ export class CustomWokaPreviewer extends Phaser.GameObjects.Container {
|
||||
this.config = config;
|
||||
|
||||
this.sprites = {
|
||||
[CustomWokaBodyPart.Accessory]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, ""),
|
||||
[CustomWokaBodyPart.Body]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, ""),
|
||||
[CustomWokaBodyPart.Clothes]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, ""),
|
||||
[CustomWokaBodyPart.Eyes]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, ""),
|
||||
[CustomWokaBodyPart.Hair]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, ""),
|
||||
[CustomWokaBodyPart.Hat]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, ""),
|
||||
[CustomWokaBodyPart.Accessory]: this.scene.add
|
||||
.sprite(this.config.bodyPartsOffsetX, 0, "")
|
||||
.setVisible(false),
|
||||
[CustomWokaBodyPart.Body]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, "").setVisible(false),
|
||||
[CustomWokaBodyPart.Clothes]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, "").setVisible(false),
|
||||
[CustomWokaBodyPart.Eyes]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, "").setVisible(false),
|
||||
[CustomWokaBodyPart.Hair]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, "").setVisible(false),
|
||||
[CustomWokaBodyPart.Hat]: this.scene.add.sprite(this.config.bodyPartsOffsetX, 0, "").setVisible(false),
|
||||
};
|
||||
|
||||
this.updateSprite("accessory1", CustomWokaBodyPart.Accessory);
|
||||
this.updateSprite("body1", CustomWokaBodyPart.Body);
|
||||
this.updateSprite("clothes4", CustomWokaBodyPart.Clothes);
|
||||
this.updateSprite("eyes5", CustomWokaBodyPart.Eyes);
|
||||
this.updateSprite("hair3", CustomWokaBodyPart.Hair);
|
||||
this.updateSprite("hat2", CustomWokaBodyPart.Hat);
|
||||
// this.updateSprite("accessory1", CustomWokaBodyPart.Accessory);
|
||||
// this.updateSprite("body1", CustomWokaBodyPart.Body);
|
||||
// this.updateSprite("clothes4", CustomWokaBodyPart.Clothes);
|
||||
// this.updateSprite("eyes5", CustomWokaBodyPart.Eyes);
|
||||
// this.updateSprite("hair3", CustomWokaBodyPart.Hair);
|
||||
// this.updateSprite("hat2", CustomWokaBodyPart.Hat);
|
||||
|
||||
this.background = this.scene.add.graphics();
|
||||
this.drawBackground();
|
||||
@@ -74,36 +85,12 @@ export class CustomWokaPreviewer extends Phaser.GameObjects.Container {
|
||||
this.moving = moving;
|
||||
}
|
||||
|
||||
private drawBackground(): void {
|
||||
this.background.clear();
|
||||
this.background.fillStyle(0xffffff);
|
||||
this.background.lineStyle(this.config.borderThickness, 0xadafbc);
|
||||
|
||||
this.background.fillRect(-this.SIZE / 2, -this.SIZE / 2, this.SIZE, this.SIZE);
|
||||
this.background.strokeRect(-this.SIZE / 2, -this.SIZE / 2, this.SIZE, this.SIZE);
|
||||
}
|
||||
|
||||
private animate(): void {
|
||||
for (const bodyPartKey in this.sprites) {
|
||||
const sprite = this.sprites[bodyPartKey as CustomWokaBodyPart];
|
||||
if (!sprite.anims) {
|
||||
console.error("ANIMS IS NOT DEFINED!!!");
|
||||
return;
|
||||
}
|
||||
const textureKey = sprite.texture.key;
|
||||
if (
|
||||
this.moving &&
|
||||
(!sprite.anims.currentAnim || sprite.anims.currentAnim.key !== this.animationDirection)
|
||||
) {
|
||||
sprite.play(textureKey + "-" + this.animationDirection + "-" + PlayerAnimationTypes.Walk, true);
|
||||
} else if (!this.moving) {
|
||||
sprite.anims.play(textureKey + "-" + this.animationDirection + "-" + PlayerAnimationTypes.Idle, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public updateSprite(textureKey: string, bodyPart: CustomWokaBodyPart): void {
|
||||
this.sprites[bodyPart].setTexture(textureKey);
|
||||
this.sprites[bodyPart].setTexture(textureKey).setVisible(textureKey !== "");
|
||||
console.log(this.sprites[bodyPart].texture.key);
|
||||
if (textureKey === "") {
|
||||
return;
|
||||
}
|
||||
getPlayerAnimations(textureKey).forEach((d) => {
|
||||
this.scene.anims.create({
|
||||
key: d.key,
|
||||
@@ -125,4 +112,35 @@ export class CustomWokaPreviewer extends Phaser.GameObjects.Container {
|
||||
public getAnimationDirection(): PlayerAnimationDirections {
|
||||
return this.animationDirection;
|
||||
}
|
||||
|
||||
private drawBackground(): void {
|
||||
this.background.clear();
|
||||
this.background.fillStyle(0xffffff);
|
||||
this.background.lineStyle(this.config.borderThickness, 0xadafbc);
|
||||
|
||||
this.background.fillRect(-this.SIZE / 2, -this.SIZE / 2, this.SIZE, this.SIZE);
|
||||
this.background.strokeRect(-this.SIZE / 2, -this.SIZE / 2, this.SIZE, this.SIZE);
|
||||
}
|
||||
|
||||
private animate(): void {
|
||||
for (const bodyPartKey in this.sprites) {
|
||||
const sprite = this.sprites[bodyPartKey as CustomWokaBodyPart];
|
||||
if (!sprite.anims) {
|
||||
console.error("ANIMS IS NOT DEFINED!!!");
|
||||
return;
|
||||
}
|
||||
const textureKey = sprite.texture.key;
|
||||
if (textureKey === "__MISSING") {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
this.moving &&
|
||||
(!sprite.anims.currentAnim || sprite.anims.currentAnim.key !== this.animationDirection)
|
||||
) {
|
||||
sprite.play(textureKey + "-" + this.animationDirection + "-" + PlayerAnimationTypes.Walk, true);
|
||||
} else if (!this.moving) {
|
||||
sprite.anims.play(textureKey + "-" + this.animationDirection + "-" + PlayerAnimationTypes.Idle, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,15 +37,13 @@ export class WokaBodyPartSlot extends GridItem {
|
||||
.rectangle(0, 0, this.SIZE, this.SIZE, this.config.color)
|
||||
.setStrokeStyle(this.config.borderThickness, this.config.borderColor);
|
||||
|
||||
this.bodyImage = this.scene.add.image(
|
||||
offsetX,
|
||||
offsetY,
|
||||
config.bodyImageKey ?? `body${Math.floor(Math.random() * 33) + 1}`
|
||||
);
|
||||
this.bodyImage = this.scene.add
|
||||
.image(offsetX, offsetY, config.bodyImageKey ?? "")
|
||||
.setVisible(config.imageKey !== undefined);
|
||||
|
||||
this.image = this.scene.add
|
||||
.image(offsetX, offsetY, config.imageKey ?? "")
|
||||
.setVisible(config.imageKey !== undefined);
|
||||
.setVisible(config.bodyImageKey !== undefined);
|
||||
|
||||
this.setSize(this.SIZE + this.config.borderThickness, this.SIZE + this.config.borderThickness);
|
||||
|
||||
@@ -59,14 +57,22 @@ export class WokaBodyPartSlot extends GridItem {
|
||||
this.scene.add.existing(this);
|
||||
}
|
||||
|
||||
public setBodyTexture(textureKey: string, frame?: string | number): void {
|
||||
this.bodyImage.setTexture(textureKey, frame);
|
||||
public setTextures(bodyTextureKey?: string, imageTextureKey?: string): void {
|
||||
this.setBodyTexture(bodyTextureKey);
|
||||
this.setImageTexture(imageTextureKey);
|
||||
}
|
||||
|
||||
public setBodyTexture(textureKey?: string, frame?: string | number): void {
|
||||
this.bodyImage.setVisible(textureKey !== undefined && textureKey !== "");
|
||||
if (textureKey) {
|
||||
this.bodyImage.setTexture(textureKey, frame);
|
||||
}
|
||||
}
|
||||
|
||||
public setImageTexture(textureKey?: string, frame?: string | number): void {
|
||||
this.image.setVisible(textureKey !== undefined || textureKey !== "");
|
||||
this.image.setVisible(textureKey !== undefined && textureKey !== "");
|
||||
if (textureKey) {
|
||||
this.bodyImage.setTexture(textureKey, frame);
|
||||
this.image.setTexture(textureKey, frame);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user