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

Fix removed FGD bases creeping into final output through sorted_ents #34

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

ozxybox
Copy link
Contributor

@ozxybox ozxybox commented Nov 7, 2024

This fixes an issue i was having where entites removed from an FGD were creeping back in. This was breaking my work on using @ExtendClass as i would find entries duplicated or removed bases appearing`

This would manifest looking something like this

@BaseClass = BaseEntityInputs ...
// much later on
@ExtendClass = BaseEntityInputs ...

Not sure if this is the greatest fix, as it might slow down this function a little!

@ozxybox
Copy link
Contributor Author

ozxybox commented Nov 7, 2024

Seems like i tripped a lot of tests? Was this the intended behavior then?

@TeamSpen210
Copy link
Owner

It is yes, see the comment below. FGD bases are kinda annoying, since @BaseClass just evaulates them immediately. You can have silly situations like a base class with the same name as the child entity, making said child shadow that parent. Not very conducive to saving again. There's the _fix_missing_bases() method there which renames them to fix that. Maybe I should make that public?

Probably better to make sure you remove entities from bases if you're removing them from the FGD itself.

@ozxybox
Copy link
Contributor Author

ozxybox commented Nov 7, 2024

Ahhh okay. With my particular use case, I need to keep the base class on the entity itself, but not export the base class. This is so I can do things such as extend an existing entity, giving it a new base class, or rely on a base class from the parent repo without having to include that base class.

@TeamSpen210
Copy link
Owner

Ah, if you just want to have the base() definition exported, but not the actual base class, you can put a string in the bases attribute.

@TeamSpen210 TeamSpen210 closed this Nov 9, 2024
@ozxybox
Copy link
Contributor Author

ozxybox commented Nov 11, 2024

Sorry for the slow response here! I went to try converting it all to strings, but it seems like sorted_ents doesn't quite like having to deal with strings. It throws an exception when I do so. Should I just modify the function to accept strings, or is there a different way I should be doing this?

  File "E:\Dev\srctools\src\srctools\fgd.py", line 2303, in export
    for ent_def in self.sorted_ents():
  File "E:\Dev\srctools\src\srctools\fgd.py", line 2126, in sorted_ents
    raise ValueError(f'Unevaluated base: {base} in {ent.classname}!')

@TeamSpen210
Copy link
Owner

Ah, I guess I didn't think you would want to do this, probably should get rid of that error then yes.

@TeamSpen210 TeamSpen210 reopened this Nov 11, 2024
@ozxybox ozxybox force-pushed the fix-sorted-entities-export branch from 15e627f to e811392 Compare November 11, 2024 20:33
@ozxybox
Copy link
Contributor Author

ozxybox commented Nov 11, 2024

I've pushed a fix now that works for what I'm trying to do

@TeamSpen210 TeamSpen210 merged commit f2ac357 into TeamSpen210:master Nov 11, 2024
8 checks passed
@ozxybox
Copy link
Contributor Author

ozxybox commented Nov 12, 2024

Thanks for merging this!

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.

2 participants