Replacing A Base Function

The_goggles_do_nothing

King
Supporter
Joined
Oct 26, 2021
Messages
734
I want to replace a single function in the base code.

Base\modules\core\ui\utilities\utilities-image.js

Code:
                <ImportFiles>
                    <!-- Replacing existing ui code or new css files (not code) -->
                    <Item>ui/utilities/utilities-image.js</Item>
                </ImportFiles>

The my replacement:

Code:
import { Icon } from '/core/ui/utilities/utilities-image.js';
function goggles_getCivSymbolFromCivilizationType(civilization) {
    const civDef = GameInfo.Civilizations.lookup(civilization);
    const iconURL = UI.getIconURL(civDef.CivilizationType, "CIVILIZATION");
    return iconURL;
}

Icon.prototype.getCivSymbolFromCivilizationType = goggles_getCivSymbolFromCivilizationType;
//# sourceMappingURL=file:///core/ui/utilities/utilities-image.js.map

I know the code works because I can change it in the original file, and the I know the game is using my file the game now gets stuck on the loading screen.

Thanks in advance,
 
Last edited:
I haven't been able to override part of the file using <UIScripts>, I think because it's in core. When I totally replace the file using <ImportFiles> with the change it works. Not idea but I'm frustrated
 
I noticed that mod files sometimes get loaded BEFORE base scripts, so the overriding doesn't work for some of them.
 
If you want to override a PART of a file, you should not name your file the same path/file as the original. You need the original not to get overwritten at all, so your script should REFERENCE their url (as you do in your example), but should not use ImportFiles (which overwrites), unless it has a different path. UIScripts is probably what you want to do.
 
Back
Top Bottom