Exports methods - hovgaardgames/startupcompany GitHub Wiki
Exports methods
For our mod, we can use the following methods on differents steps.
Name |
---|
exports.initialize |
exports.onBackgroundWorkerStart |
exports.onLoadGame |
exports.onNewDay |
exports.onNewHour |
exports.onUnsubscribe |
exports.views |
initialize
exports.initialize
is called when the game is initializing mods. That's in this method that you will be able to manipulate game data or just declare your own mod's logic. Note that the settings are not loaded at this point.
exports.initialize = modPath => {
// Do some logic here
};
modPath
contains the absolute path to your mod folder (e.g. C:\Steam\steamapps\common\Startup Company\resources\app\mods\my_mod\
).
onBackgroundWorkerStart
exports.onBackgroundWorkerStart
is called in the background to process some logic.
Startup Company is doing a lot of it's logic in a background worker. This is done to decrease UI lag.
If you're manipulating with game objects like RackDevices, Servers, ProductTypes, Competitors, EmployeeTypes etc, you will have to update the background worker too.
Here's an example of adding a custom product type :
exports.initialize = modPath => {
// Setup new product type when initializing mod
ProductTypeNames['MyNewProductType'] = 'MyNewProductType';
ProductTypes.push({
name: ProductTypeNames.MyNewProductType,
incomePerUserPerDay: 0.06,
faIcon: 'fa-share-square-o',
features: [
FeatureNames.LandingPage,
FeatureNames.CommentFunctionality
],
audienceMatches: [
MarketingInterests.Travel
]
});
}
exports.onBackgroundWorkerStart = modPath => {
// Setup new product type in background worker.
ProductTypeNames['MyNewProductType'] = 'MyNewProductType';
ProductTypes.push({
name: ProductTypeNames.MyNewProductType,
incomePerUserPerDay: 0.06,
faIcon: 'fa-share-square-o',
features: [
FeatureNames.LandingPage,
FeatureNames.CommentFunctionality
],
audienceMatches: [
MarketingInterests.Travel
]
});
}
onLoadGame
exports.onLoadGame
is called when the savegame is loaded. You can now access to the settings which are provided as parameter.
exports.onLoadGame = settings => {
// Do some logic here
};
onNewDay
exports.onNewDay
is called each in-game day.
exports.onNewDay = settings => {
// Do some logic here
};
onNewHour
exports.onNewHour
is called each in-game hour. Be careful when using it, this method is called a lot of times, we highly recommend you to have a performant your logic here, otherwise the game could have lag.
exports.onNewHour = settings => {
// Do some logic here
};
onUnsubscribe
exports.onUnsubscribe
is called when the user is unsubscribing of the mod.
If you're manipulating with internal objects or arrays it's important to test if player's savegames are still working after unsubscribing. To clean up, we can use the onUnsubscribe
event. The method only returns a done
method, that you have to call when you are done cleaning up.
Here is an example of how you clean up all savegames :
exports.onUnsubscribe = done => {
// Restores everything to prepare for unsubscription from Steam Workshop
// Get savegames
let savegames = Helpers.GetSaveGames();
// Check each savegames that can contains my_mod settings
savegames.forEach((savegame, index) => {
// Load settings from the savegame
let settings = Helpers.LoadJsonFile(savegame.fileName);
// TODO : Clean up things related about your mod (like removed competitors, brands, etc)
// In the following example, it will remove all settings related to my_mod
//delete settings.my_mod;
// Save cleaned file
Helpers.SaveJsonToFile(savegame.fileName, settings);
// If this is the last savegame, tell we are done
if (index === savegames.length - 1) {
done();
}
});
}
views
exports.views
isn't a method. It allows you to create a view and his logic.
let _modPath;
exports.initialize = modPath => {
_modPath = modPath;
// Create view and logic
exports.views = [{
name: 'my_mod',
viewPath: _modPath + 'view.html',
controller: ["$scope", function ($scope) {
// Do some logic related to the view
}]
}];
};
Don't forget to add a menu item linked with this view, otherwise your view will not be called at anytime.