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

Generate subclasses #138

Draft
wants to merge 1 commit into
base: current
Choose a base branch
from

Conversation

sparr
Copy link
Contributor

@sparr sparr commented Sep 12, 2024

As discussed on Discord, this is my first attempt at generating subclasses.

Anywhere the json docs for an attribute or method have a subclasses field, we currently just note that in the docs, the same way the official html docs do, e.g. "Can only be used if this is Ghost, CombatRobot, HighlightBox, SmokeWithTrigger or Sticker". This PR changes that behavior to instead generate new classes. Instead of one LuaEntity with dozens of "Can only be used if..." fields and methods, we have LuaEntity.base with the parts that are not specific to any subclasses, and new classes such as LuaEntity.Spawner and LuaEntity.CombatRobot with the subclass-specific parts. Then to wrap it all up the original LuaEntity identifier is now an alias that unions all the subclasses with the base class, similar to how variant_parameter_groups are currently handled.

Notable places to look in the generated output are LuaEntity, LuaEntityPrototype, LuaGuiElement, and LuaGuiElement_funcs, although the effects are wide reaching.

---@alias LuaEntity (LuaEntity.Spawner)|(LuaEntity.Unit)|(LuaEntity.ProgrammableSpeaker)|(LuaEntity.Character)|(...|(LuaEntity.base)

---@alias LuaGuiElement_funcs (LuaGuiElement_funcs.drop-down)|(LuaGuiElement_funcs.list-box)|(LuaGuiElement_funcs.tabbed-pane)|...|(LuaGuiElement_funcs.base)

I haven't done a thorough test or diff between the old and new generated output. I'm posting this before I fall asleep in case there's useful review feedback I can act on when I pick this back up soon.

I'm also not sure I like the way the _funcs naming scheme ends up with subclasses.

@sparr sparr force-pushed the generate_subclasses branch from dbcb1e7 to 72966a7 Compare September 12, 2024 06:35
@sparr
Copy link
Contributor Author

sparr commented Sep 14, 2024

I have identified a failure mode.

Fields and methods with "subclasses": "TransportBeltConnectable" need to be available on belt, splitter, etc. This relationship is codified in the prototypes api as follows:

"name": "TransportBeltPrototype",
"parent": "TransportBeltConnectablePrototype",

The obvious approach which would work in this scenario but may break or produce inaccurate results in other scenarios would be to map runtime LuaFoo or LuaFoo.base or LuaBase.Foo to prototype FooPrototype, then get FooPrototype.parent e.g. FooParentType, then map that back to runtime LuaParentType. I am investigating / considering / discussing on Discord whether and how to potentially follow this relationship safely and reliably.

@sparr
Copy link
Contributor Author

sparr commented Oct 21, 2024

I'll try to revisit this with 2.0, and am open to any feedback before that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant