Skip to content

Addressed the legacy Avatar situation with Transform#882

Open
CapoMK25 wants to merge 1 commit into
devfrom
799-bug-avatardata-in-the-friend-request-data-is-in-the-old-format
Open

Addressed the legacy Avatar situation with Transform#882
CapoMK25 wants to merge 1 commit into
devfrom
799-bug-avatardata-in-the-friend-request-data-is-in-the-old-format

Conversation

@CapoMK25

Copy link
Copy Markdown
Collaborator

Brief description

#799

Addresses that issue with the absolute bare minimum amount of changes from the baseline setup. I incorporated the use of @Transform here to address the legacy AvatarData meshing with the new one.

Each unit test passes miraculously by default as well.

Change list

  • Adds the use of Transform from the class-transformer library
  • Adds it to each AvatarPiece

Backend testing was done using a different approach, here's the output:

[capomk@lianli Altzone-Server]$ npx ts-node -e "

import 'reflect-metadata';

import { plainToInstance } from 'class-transformer';

import { AvatarDto } from './src/player/dto/avatar.dto';



const legacyData = {

  head: 1,

  hair: 2,

  eyes: 3,

  nose: 1,

  mouth: 2,

  eyebrows: 1,

  clothes: 4,

  feet: 1,

  hands: 2,

  skinColor: '#FAD9B5'

};



const result = plainToInstance(AvatarDto, legacyData);

console.log('Transformed Avatar:\n', JSON.stringify(result, null, 2));

"

npm notice run altzone-server@1.0.0 npx

npm notice run 'ts-node' -e 

npm notice run import 'reflect-metadata';

npm notice run import { plainToInstance } from 'class-transformer';

npm notice run import { AvatarDto } from './src/player/dto/avatar.dto';

npm notice run

npm notice run const legacyData = {

npm notice run   head: 1,

npm notice run   hair: 2,

npm notice run   eyes: 3,

npm notice run   nose: 1,

npm notice run   mouth: 2,

npm notice run   eyebrows: 1,

npm notice run   clothes: 4,

npm notice run   feet: 1,

npm notice run   hands: 2,

npm notice run   skinColor: '#FAD9B5'

npm notice run };

npm notice run

npm notice run const result = plainToInstance(AvatarDto, legacyData);

npm notice run console.log('Transformed Avatar:\n', JSON.stringify(result, null, 2));

Transformed Avatar:

 {

  "head": {

    "id": 1,

    "color": "#ffffff"

  },

  "hair": {

    "id": 2,

    "color": "#ffffff"

  },

  "eyes": {

    "id": 3,

    "color": "#ffffff"

  },

  "nose": {

    "id": 1,

    "color": "#ffffff"

  },

  "mouth": {

    "id": 2,

    "color": "#ffffff"

  },

  "eyebrows": {

    "id": 1,

    "color": "#ffffff"

  },

  "clothes": {

    "id": 4,

    "color": "#ffffff"

  },

  "feet": {

    "id": 1,

    "color": "#ffffff"

  },

  "hands": {

    "id": 2,

    "color": "#ffffff"

  },

  "skinColor": "#FAD9B5"

}

[capomk@lianli Altzone-Server]$ 

Another run right after to see that this sticks:

[capomk@lianli Altzone-Server]$ npx ts-node -e "

import 'reflect-metadata';

import { plainToInstance } from 'class-transformer';

import { AvatarDto } from './src/player/dto/avatar.dto';



const mixedData = {

  head: { id: 5, color: '#ff0000' }, // New format

  hair: 2,                           // Legacy format

  skinColor: '#FAD9B5'

};



console.log(JSON.stringify(plainToInstance(AvatarDto, mixedData), null, 2));

"

npm notice run altzone-server@1.0.0 npx

npm notice run 'ts-node' -e 

npm notice run import 'reflect-metadata';

npm notice run import { plainToInstance } from 'class-transformer';

npm notice run import { AvatarDto } from './src/player/dto/avatar.dto';

npm notice run

npm notice run const mixedData = {

npm notice run   head: { id: 5, color: '#ff0000' }, // New format

npm notice run   hair: 2,                           // Legacy format

npm notice run   skinColor: '#FAD9B5'

npm notice run };

npm notice run

npm notice run console.log(JSON.stringify(plainToInstance(AvatarDto, mixedData), null, 2));

{

  "head": {

    "id": 5,

    "color": "#ff0000"

  },

  "hair": {

    "id": 2,

    "color": "#ffffff"

  },

  "skinColor": "#FAD9B5"

}

[capomk@lianli Altzone-Server]$  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant