Book a Demo

Author Topic: How read class' attribute list in code generation template  (Read 2918 times)

mgodoy-br

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
How read class' attribute list in code generation template
« on: October 05, 2020, 06:15:55 am »
I'm creating a MDG technology and have evolved a lot in generate PIM to PSM.

This time around, I intend to get a couple of attribute under a certain stereotype and generate code using them in a certain operation that I've chosen.

This is my PIM's source class. My stereotypes have tagged values that support resources in my transformation template:



And that is my generated PSM so far:



I wanna all of actionCharacterSetAttribute attribute in Cobaia source class be generate in my CobaiaEnemyCharacter.InitializeActionCharacterSet operation. This way, I intent to initialize an internal cache with those attributes.

I hope producing something like this (the values I get from stereotype's tagged values that didn't show up in image bellow):

Code: [Select]
protected override void InitializeActionCharacterSet(ActionCharacterSet actionCharacterSet)
{
     actionCharacterSet.Register("punch-animation", ActionCharacterEnum.PUNCH);
     actionCharacterSet.Register("walk-animation", ActionCharacterEnum.WALK);
...

How can I achieve this? A little note: None of actionCharacterSetAttribute will be in destination code.
« Last Edit: October 05, 2020, 09:56:13 am by mgodoy-br »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How read class' attribute list in code generation template
« Reply #1 on: October 05, 2020, 09:06:19 am »
Code: [Select]
%list="Attribute" @separator="\n" @indent="\t"%

mgodoy-br

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: How read class' attribute list in code generation template
« Reply #2 on: October 05, 2020, 09:32:15 am »
Hi, Eve. I'd already tried that. It doesn't work, because the result is the rendering of attributes of CobaiaEnemyCharacter (the PSM renegated). Actually, I wanna get punch-animation and walk-animation attributes of Cobaia PIM class.

When I run using "list" template, is rendered:

Code: [Select]
private HealthManager _healthManager
What I want is a way to do:

Code: [Select]
protected override void InitializeActionCharacterSet(ActionCharacterSet actionCharacterSet)
{
     actionCharacterSet.Register("punch-animation", ActionCharacterEnum.PUNCH);
     actionCharacterSet.Register("walk-animation", ActionCharacterEnum.WALK);

     (n attributes with sterotype actionCharacterSetAttribute)
...

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How read class' attribute list in code generation template
« Reply #3 on: October 05, 2020, 10:36:55 am »
Edit the Attribute template to print what you want for each of the attributes.

If you want to only list attributes with a particular stereotype you can either %endTemplate% early in the attribute template or filter the list to the stereotype you want.

mgodoy-br

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: How read class' attribute list in code generation template
« Reply #4 on: October 06, 2020, 10:47:17 am »
I afraid I can't do it... Otherwise, such attributes that I just want to use to populate my variable inside my Operation is going to be rendered in my class, and for such attributes I don't want to do that.

However, I've got turn them out in Tags so that it can be attached in my operation.

Sounds good so far, but I've couldn't figure out how to write a template for Tag elements. That'd solved my problem. 

My MDG's Attribute stereotyped template turned into like this:

Code: [Select]
Tag
{
name="%attName%"
value="%attTag:"animationMap"%"
}

My chalenge now is in my Code“s Operation template:

Code: [Select]
%if opName == "InitializeActionCharacterSet"%
/*
%loop in opTag list ????%
opTag:i ???
*/
%else%

Is there some way to handle the Tag?
« Last Edit: October 06, 2020, 11:21:24 pm by mgodoy-br »