Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let objects be declared as abstract even if they contain no members #61

Closed
heinezen opened this issue May 20, 2019 · 7 comments
Closed
Labels
proposal pending discussion about something to do specification involves the nyan language specification

Comments

@heinezen
Copy link
Member

heinezen commented May 20, 2019

According to the specification, nyan objects "remain abstract until all members have values" ("A nyan::Object is "abstract" iff it contains at least one undefined member"). Some of the openage API objects would require objects to be abstract that contain no members. These objects are often used as generalization objects that should be inherited from, but not be used on their own.

Examples : GameEntityType, DiplomaticStance, TradeRoute, DropoffType

Proposed solution: Use the same idea as in #58 and introduce parameters for sets. In this case the definition could look like this: set(typename, only_children=True)

For single references, use a new child container type: child(typename)

@heinezen heinezen added proposal pending discussion about something to do specification involves the nyan language specification labels May 20, 2019
@TheJJ
Copy link
Member

TheJJ commented May 21, 2019

If the generalization objects don't add any member, why are they needed then?

@heinezen
Copy link
Member Author

heinezen commented May 21, 2019

Mostly, modders are expected to inherit from the generalization object for a specialized case and not use the generalization object itself. For example, in AoE2 we derive the stances Enemy, Neutral, Ally from DiplomaticStance which is used in DiplomaticAbility:

DiplomaticAbility(Ability):
    diplomatic_stances : set(DiplomaticStance)

It should only be possible to add Enemy, Neutral, Ally and not engine.DiplomaticStance.

@TheJJ
Copy link
Member

TheJJ commented May 21, 2019

And DiplomaticStance doesn't add any new (undefined) members? If it does, I think it would be better to allow any other child object there, e.g. if a mod adds another stance like TradePartner which is still an enemy but you can trade with. If it doesn't, what there's surely a common parent object that can be used instead?

@heinezen
Copy link
Member Author

heinezen commented Jun 4, 2019

We agreed to introduce a new only_children parameter for sets, similar to #58. In the set declaration this parameter is optional and can be either true or false. See comment below

Example:

DiplomaticAbility(Ability):
    stances : set(DiplomaticStance, only_children=True)

@heinezen
Copy link
Member Author

Turns out this only solves the problem for sets. We have situations in the API where a member has the nyan::Object type, but only its children should be referenced.

Example:

FlatAttributeChange(ContinuousEffect):
    type              : AttributeChangeType
    min_change_rate   : optional(AttributeRate)
    max_change_rate   : optional(AttributeRate)
    change_rate       : AttributeRate
    ignore_protection : set(ProtectingAttribute)

The type member should only be allowed to reference children of AttributeChangeType.

@TheJJ
Copy link
Member

TheJJ commented Jun 12, 2019

Possible solution: Another container type like childs, which behaves similar to optional, but enforces that only child objects are assigned:

type : childs(AttributeChangeType)

@TheJJ TheJJ changed the title Let objects be declared as abstract even if they contain no members childs(type) to allow children only Sep 8, 2019
@TheJJ TheJJ changed the title childs(type) to allow children only Let objects be declared as abstract even if they contain no members Sep 8, 2019
@TheJJ
Copy link
Member

TheJJ commented Sep 8, 2019

I've created #65 to track this feature.

@TheJJ TheJJ closed this as completed Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal pending discussion about something to do specification involves the nyan language specification
Projects
None yet
Development

No branches or pull requests

2 participants