My Wonders Screen and Claimed Wonders Notation mods are very similar in the functionality they're providing but I opted to keep them separate as their scope is quite different. The logic for tracking wonders under construction is significantly more complicated than tracking completed wonders and I didn't want to duplicate the logic for that so l looked into using dynamic imports to allow the Claimed Wonders Notation mod to utilize the data model from the Wonders Screen mod if it exists.
Mod links:
In the initialization for the Claimed Wonders Notation mod it uses a dynamic import to check for the existence of the Wonders Screen mod. If so it passes the imported model object to the initialization function. The wonder screen model also defines a version for compatibility checks (I had to add an additional field in the data model). This ensures that it's only using the Wonder Screen's data model when it is compatible with its requirements.
In the initialization it's then either doing the setup required for the simple wonder tracking it implements or just setting an internal reference to the Wonder Screen's model. Then when performing checks for existing wonders it conditionally uses its own internal logic or references the Wonder Screen's model.
Mod links:
Completed wonders are noted on screens that display civics & techs.
In the initialization for the Claimed Wonders Notation mod it uses a dynamic import to check for the existence of the Wonders Screen mod. If so it passes the imported model object to the initialization function. The wonder screen model also defines a version for compatibility checks (I had to add an additional field in the data model). This ensures that it's only using the Wonder Screen's data model when it is compatible with its requirements.
JavaScript:
engine.whenReady.then(() => {
import('/wonders-screen/code/wonders-screen-model.js').then(module => {
if (module.default._version && module.default._version >= 2)
{
WonderTrackerInstance.AttachToGame(module.default);
}
else
{
WonderTrackerInstance.AttachToGame();
}
}).catch((_err) => {
WonderTrackerInstance.AttachToGame();
});
});
In the initialization it's then either doing the setup required for the simple wonder tracking it implements or just setting an internal reference to the Wonder Screen's model. Then when performing checks for existing wonders it conditionally uses its own internal logic or references the Wonder Screen's model.
JavaScript:
IsCompletedIcon(wonderIcon)
{
if (this._wonderModel)
{
const data = this._wonderModel.wonderData;
for (const w of data)
{
if (w.icon == wonderIcon)
{
return w.completed;
}
}
return false;
}
else
{
return this.completedWondersIcons.includes(wonderIcon);
}
}