Skip to content

Commit

Permalink
Allow multiple possible loading screens, including from mods
Browse files Browse the repository at this point in the history
  • Loading branch information
RenechCDDA committed Sep 13, 2024
1 parent dd272dd commit 8b0b2e8
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 11 deletions.
13 changes: 13 additions & 0 deletions data/mods/alternate_loading_images/modinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"type": "MOD_INFO",
"id": "alternate_loading_images",
"name": "Alternate loading screen images",
"authors": [ "RenechCDDA" ],
"description": "Provides more possible images for the graphical loading screen.",
"category": "graphical",
"dependencies": [ "dda" ],
"loading_images": [ "loadscreen_by_db48x.png", "loadscreen_by_vetall812.png" ],
"path": ""
}
]
2 changes: 1 addition & 1 deletion data/mods/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"id": "dev:default",
"name": "default",
"description": "contains all the mods recommended by the developers",
"dependencies": [ "dda", "no_npc_food", "personal_portal_storms", "no_fungal_growth", "No_Rail_Stations" ]
"dependencies": [ "dda", "no_npc_food", "personal_portal_storms", "no_fungal_growth", "No_Rail_Stations", "alternate_loading_images" ]
}
]
32 changes: 25 additions & 7 deletions doc/MODDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,34 @@ A barebones `modinfo.json` file looks like this:
{
"type": "MOD_INFO",
"id": "Mod_ID",
"name": "Mod's Display Name",
"authors": [ "Your name here", "Your friend's name if you want" ],
"description": "Your description here",
"category": "content",
"dependencies": [ "dda" ]
"name": "Mod's Display Name"
}
]
````

This is the absolute bare minimum, but you may want to add `authors`(You!), a `description` and a `category`. See below for more possibilities.

### All MOD_INFO fields
Here is a full list of supported values for MOD_INFO:
````json
[
{
"type": "MOD_INFO", // Mandatory, you're making one of these!
"id": "Mod_ID", // Mandatory, unique id for your mod. You should not use the same id as any other mod.
"name": "Mod's Display Name", // Mandatory.
"authors": [ "Me", "A really cool friend" ], // Optional, but you probably want to put your name here. More than one entry can be added, as shown.
"description": "The best mod ever!", // Optional
"category": "graphical", // Optional, see below for a full list of supported values. The category is just for information purposes, so don't worry if your mod might fit more than one category.
"dependencies": [ "dda" ], // Optional. What other mods are required for this mod to function? If your mod depends on another one to work properly, adding that mod's `id` attribute to the array causes Cataclysm to force that mod to load before yours.
"loading_images": [ "cool.png", "cool2.png" ], // Optional. Filenames for any loading screen images the mod may have. Loading screens are only present on the graphical/"tiles" version. Only supports .png files. Actual loading screen image will be picked randomly from among all mod loading screens, including other loaded mods that have loading screens.
"version": "1.3.bacon", // Optional. For informational purposes only. No versioning system is provided, so whatever you put here is up to you. Feel free to name your versions after ice cream.
"core": false, // Optional, default false. Core mods will be loaded before anything else. Used for DDA, third-party use will not be supported.
"obsolete": false, // Optional, default false. Obsolete mods are loaded for legacy saves but cannot be used when starting new worlds
"path": "my_mod_files/" // Optional, this directory relative to modinfo.json's location will be considered the mod's actual directory. e.g. if modinfo.json is located at C:\CDDA\my_mod\modinfo.json, then the mod files would be considered to be at C:\CDDA\my_mod\my_mod_files\. A file such as C:\CDDA\my_mod\some_other_file.json would be ignored, it isn't located inside the specified directory.
}
]
````

The `category` attribute denotes where the mod will appear in the mod selection menu. These are the available categories to choose from, with some examples chosen from mods that existed when this document was written. Pick whichever one applies best to your mod when writing your modinfo file.
- `content` - A mod that adds a lot of stuff. Typically reserved for large mods (eg: Core game files, Aftershock)
- `total_conversion` - A mod that fundamentally changes the game. In particular, the assumption is that a player should not use two total conversion mods at the same time, and so they will not be tested together. However, nothing prevents players from using more than one if they wish. (eg: Dark Skies Above)
Expand All @@ -44,8 +64,6 @@ The `category` attribute denotes where the mod will appear in the mod selection
- `monster_exclude` - A mod that stops certain monster varieties from spawning in the world (eg: No fungal monsters, No monsters)
- `graphical` - A mod that adjusts game graphics in some way (eg: Graphical overmap)

The `dependencies` attribute is used to tell Cataclysm that your mod is dependent on something present in another mod. If you have no dependencies outside of the core game, then just including `dda` in the list is good enough. If your mod depends on another one to work properly, adding that mod's `id` attribute to the array causes Cataclysm to force that mod to load before yours.

## Actually adding things to your mod
Now that you have a basic mod, you can get around to actually putting some stuff into it!

Expand Down
1 change: 0 additions & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3226,7 +3226,6 @@ void game::load_packs( const std::string &msg, const std::vector<mod_id> &packs
}
load_data_from_dir( mod.path, mod.ident.str() );
}
loading_ui::done();

std::unordered_set<mod_id> removed_mods {
MOD_INFORMATION_Graphical_Overmap // Removed in 0.I
Expand Down
27 changes: 25 additions & 2 deletions src/loading_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui/imgui.h"
#undef IMGUI_DEFINE_MATH_OPERATORS
#include "mod_manager.h"
#include "path_info.h"
#include "sdltiles.h"
#include "sdl_wrappers.h"
#include "worldfactory.h"
#else
#include "cursesdef.h"
#endif // TILES
Expand All @@ -23,6 +25,7 @@ struct ui_state {
ImVec2 window_size;
ImVec2 splash_size;
SDL_Texture_Ptr splash;
cata_path chosen_load_img;
#else
size_t splash_width = 0;
std::vector<std::string> splash;
Expand Down Expand Up @@ -90,8 +93,25 @@ static void update_state( const std::string &context, const std::string &step )
} );

#ifdef TILES
cata_path path = PATH_INFO::gfxdir() / "cdda.png";
SDL_Surface_Ptr surf = load_image( path.get_unrelative_path().u8string().c_str() );
std::vector<cata_path> imgs;
std::vector<mod_id> &active_mod_list = world_generator->active_world->active_mod_order;
for( mod_id &some_mod : active_mod_list ) {
const MOD_INFORMATION &mod = *some_mod;
for( std::string img_name : mod.loading_images ) {
// There may be more than one file matching the name, so we need to get all of them
for( cata_path &img_path : get_files_from_path( img_name, mod.path, true ) ) {
imgs.emplace_back( img_path );
}
}
}
if( gLUI->chosen_load_img == cata_path() ) {
if( imgs.empty() ) {
gLUI->chosen_load_img = PATH_INFO::gfxdir() / "cdda.png"; //default load screen
} else {
gLUI->chosen_load_img = random_entry( imgs );
}
}
SDL_Surface_Ptr surf = load_image( gLUI->chosen_load_img.get_unrelative_path().u8string().c_str() );
gLUI->splash_size = { static_cast<float>( surf->w ), static_cast<float>( surf->h ) };
gLUI->splash = CreateTextureFromSurface( get_sdl_renderer(), surf );
gLUI->window_size = gLUI->splash_size + ImVec2{ 0.0f, 2.0f * ImGui::GetTextLineHeightWithSpacing() };
Expand Down Expand Up @@ -126,6 +146,9 @@ void loading_ui::show( const std::string &context, const std::string &step )
void loading_ui::done()
{
if( gLUI != nullptr ) {
#ifdef TILES
gLUI->chosen_load_img = cata_path();
#endif
delete gLUI->ui;
delete gLUI->bg;
delete gLUI;
Expand Down
1 change: 1 addition & 0 deletions src/mod_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ void mod_manager::load_modfile( const JsonObject &jo, const cata_path &path )
assign( jo, "dependencies", modfile.dependencies );
assign( jo, "core", modfile.core );
assign( jo, "obsolete", modfile.obsolete );
assign( jo, "loading_images", modfile.loading_images );

if( std::find( modfile.dependencies.begin(), modfile.dependencies.end(),
modfile.ident ) != modfile.dependencies.end() ) {
Expand Down
3 changes: 3 additions & 0 deletions src/mod_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ struct MOD_INFORMATION {
*/
std::set<std::string> maintainers;

/** Full filenames (including extension) of any loading screens this mod may have */
std::set<std::string> loading_images;

translation description;
std::string version;

Expand Down

0 comments on commit 8b0b2e8

Please sign in to comment.