yairm210 / Unciv

Open-source Android/Desktop remake of Civ V
Mozilla Public License 2.0
8.26k stars 1.55k forks source link

Support mods containing BaseTerrains and TerrainFeatures #2265

Closed rh-github-2015 closed 4 years ago

rh-github-2015 commented 4 years ago

Brainstorming playground - zero some testing done. Please contribute. I indend to update and collect right here in the top post.

Currently, from code inspection, mods containing new BaseTerrains, TerrainFeatures or probably Resources would be moot due to... (to be successively analyzed and correctly described):

Conclusion: Terrain in mods is unuseable, resources and improvements OK. Map editor mod support nonexistent. Map generator lacks knowledge when it could place modded terrain. All in all, however, the groundwork present is excellent.

Ideas WIP:

rh-github-2015 commented 4 years ago

I've got the mod picker for the map editor and the editor able to place mod terrain. #2240 means the stuff is listed on top, maybe I'd like a type/alphabetical order better, and the editor still omits mods that didn't contribute to the actual generated map, but that's easily fixed.

Test mod: Unciv-mod-example#5, code branch here.

rh-github-2015 commented 4 years ago

I've fixed some issues, but now I need help.

Loading a map using an improvement defined in a mod crashed because ImageGetter was still operating on the basic ruleset, and for circle colours it looks up improvements. So I had MapEditorScreen.initialize set that ruleset and call refreshAtlas like loadGame does. Works for the map editor. (Leaving out refreshAtlas here changes nothing)

But leaving the map editor results in a mostly black screen - no tiles dawn, main menu button invisible but still operational, some city banners and unit icons still visible. Next turn seems to fix this without a trace. Even stranger, leaving map editor the other way - by resizing the window - doesn't show any issue.

I should revert the ImageGetter ruleset when leaving map editor, of course, but I'm sure that won't fix the black screen - neither the ruleset nor ImageGetter.textureRegionDrawables are lacking anything, at this point they only have extra data from mods, as the original one hadn't loaded any mods...

Ideas? Should I try to get the map editor to use its own instance of ImageGetter? Or is this just a redraw issue like if this were a windows forms program and it needs a InvalidateRegion-equivalent call? I'm a little stumped.

rh-github-2015 commented 4 years ago

Turns out that disposing and reloading of the atlas file was suspect. I still don't get why letting the mods's atlants go out of scope after setTextureRegionDrawables didn't hurt before and does now.

rh-github-2015 commented 4 years ago

2287