From 112559055c8a21a51f2ea74ee7f10f52df61cee0 Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Thu, 23 Jan 2025 20:36:02 +0100 Subject: [PATCH] Added createdAt and updatedAt fields to character hair to fix cache issue --- ...06170204.ts => Migration20250123193515.ts} | 6 ++--- src/entities/base/characterHair.ts | 24 +++++++++++++++++++ .../assetManager/characterHair/update.ts | 9 ++++++- 3 files changed, 35 insertions(+), 4 deletions(-) rename migrations/{Migration20250106170204.ts => Migration20250123193515.ts} (96%) diff --git a/migrations/Migration20250106170204.ts b/migrations/Migration20250123193515.ts similarity index 96% rename from migrations/Migration20250106170204.ts rename to migrations/Migration20250123193515.ts index 1937fb2..a05f0d6 100644 --- a/migrations/Migration20250106170204.ts +++ b/migrations/Migration20250123193515.ts @@ -1,6 +1,6 @@ import { Migration } from '@mikro-orm/migrations'; -export class Migration20250106170204 extends Migration { +export class Migration20250123193515 extends Migration { override async up(): Promise { this.addSql(`create table \`map\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`width\` int not null default 10, \`height\` int not null default 10, \`tiles\` json null, \`pvp\` tinyint(1) not null default false, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); @@ -17,7 +17,7 @@ export class Migration20250106170204 extends Migration { this.addSql(`create table \`map_object\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`tags\` json null, \`origin_x\` numeric(10,2) not null default 0, \`origin_y\` numeric(10,2) not null default 0, \`is_animated\` tinyint(1) not null default false, \`frame_rate\` int not null default 0, \`frame_width\` int not null default 0, \`frame_height\` int not null default 0, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); - this.addSql(`create table \`placed_map_object\` (\`id\` varchar(255) not null, \`map_id\` varchar(255) not null, \`map_object_id\` varchar(255) not null, \`depth\` int not null default 0, \`is_rotated\` tinyint(1) not null default false, \`position_x\` int not null default 0, \`position_y\` int not null default 0, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); + this.addSql(`create table \`placed_map_object\` (\`id\` varchar(255) not null, \`map_id\` varchar(255) not null, \`map_object_id\` varchar(255) not null, \`is_rotated\` tinyint(1) not null default false, \`position_x\` int not null default 0, \`position_y\` int not null default 0, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); this.addSql(`alter table \`placed_map_object\` add index \`placed_map_object_map_id_index\`(\`map_id\`);`); this.addSql(`alter table \`placed_map_object\` add index \`placed_map_object_map_object_id_index\`(\`map_object_id\`);`); @@ -29,7 +29,7 @@ export class Migration20250106170204 extends Migration { this.addSql(`create table \`character_type\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`gender\` enum('MALE', 'FEMALE') not null, \`race\` enum('HUMAN', 'ELF', 'DWARF', 'ORC', 'GOBLIN') not null, \`is_selectable\` tinyint(1) not null default false, \`sprite_id\` varchar(255) null, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); this.addSql(`alter table \`character_type\` add index \`character_type_sprite_id_index\`(\`sprite_id\`);`); - this.addSql(`create table \`character_hair\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`gender\` varchar(255) not null default 'MALE', \`is_selectable\` tinyint(1) not null default false, \`sprite_id\` varchar(255) null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); + this.addSql(`create table \`character_hair\` (\`id\` varchar(255) not null, \`name\` varchar(255) not null, \`gender\` varchar(255) not null default 'MALE', \`is_selectable\` tinyint(1) not null default false, \`sprite_id\` varchar(255) null, \`created_at\` datetime not null, \`updated_at\` datetime not null, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); this.addSql(`alter table \`character_hair\` add index \`character_hair_sprite_id_index\`(\`sprite_id\`);`); this.addSql(`create table \`sprite_action\` (\`id\` varchar(255) not null, \`sprite_id\` varchar(255) not null, \`action\` varchar(255) not null, \`sprites\` json null, \`origin_x\` int not null default 0, \`origin_y\` int not null default 0, \`is_animated\` tinyint(1) not null default false, \`is_looping\` tinyint(1) not null default false, \`frame_width\` int not null default 0, \`frame_height\` int not null default 0, \`frame_rate\` int not null default 0, primary key (\`id\`)) default character set utf8mb4 engine = InnoDB;`); diff --git a/src/entities/base/characterHair.ts b/src/entities/base/characterHair.ts index 8a924c2..149d2e1 100644 --- a/src/entities/base/characterHair.ts +++ b/src/entities/base/characterHair.ts @@ -24,6 +24,12 @@ export class BaseCharacterHair extends BaseEntity { @ManyToOne() sprite?: Sprite + @Property() + createdAt = new Date() + + @Property() + updatedAt = new Date() + setId(id: UUID) { this.id = id return this @@ -68,4 +74,22 @@ export class BaseCharacterHair extends BaseEntity { getSprite() { return this.sprite } + + setCreatedAt(createdAt: Date) { + this.createdAt = createdAt + return this + } + + getCreatedAt() { + return this.createdAt + } + + setUpdatedAt(updatedAt: Date) { + this.updatedAt = updatedAt + return this + } + + getUpdatedAt() { + return this.updatedAt + } } diff --git a/src/events/gameMaster/assetManager/characterHair/update.ts b/src/events/gameMaster/assetManager/characterHair/update.ts index aebf6c5..7d80df2 100644 --- a/src/events/gameMaster/assetManager/characterHair/update.ts +++ b/src/events/gameMaster/assetManager/characterHair/update.ts @@ -29,7 +29,14 @@ export default class CharacterHairUpdateEvent extends BaseEvent { const characterHair = await characterHairRepository.getById(data.id) if (!characterHair) return callback(false) - await characterHair.setName(data.name).setGender(data.gender).setIsSelectable(data.isSelectable).setSprite(sprite).save() + await characterHair + .setName(data.name) + .setGender(data.gender) + .setIsSelectable(data.isSelectable) + .setSprite(sprite) + .setUpdatedAt(new Date()) + .save() + return callback(true) } catch (error) { this.logger.error(`Error updating character hair: ${error instanceof Error ? error.message : String(error)}`)