Skip to content

Commit

Permalink
Tuning: added matching tuneups by filename (on top of GUID)
Browse files Browse the repository at this point in the history
There is a new field in the .tuneup format, 'filename'. It should really be 'associated_filename', but this would be confusing with 'guid' (which should really be 'associated_guid') and changing that would be confusing with .skin format which also uses 'guid' and cannot be changed because #compatibility. C'est la vie.
  • Loading branch information
ohlidalp committed May 26, 2024
1 parent 7e9d4bb commit 5e77521
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,7 @@ void TopMenubar::RefreshTuningMenu()

tuning_saves.cqy_filter_type = LT_Tuneup;
tuning_saves.cqy_filter_guid = tuning_actor->getUsedActorEntry()->guid;
tuning_saves.cqy_filter_target_filename = tuning_actor->getTruckFileName();
tuning_saves.cqy_filter_category_id = CID_Tuneups; // Exclude auto-generated entries
tuning_saves.resetResults();
App::GetCacheSystem()->Query(tuning_saves);
Expand Down
20 changes: 19 additions & 1 deletion source/main/resources/CacheSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ void CacheSystem::ImportEntryFromJson(rapidjson::Value& j_entry, CacheEntryPtr &
{
out_entry->addonpart_filenames.insert(j_addonfname.GetString());
}

// Tuneup details
out_entry->tuneup_associated_filename = j_entry["tuneup_associated_filename"].GetString();
}

CacheValidity CacheSystem::LoadCacheFileJson()
Expand Down Expand Up @@ -622,6 +625,9 @@ void CacheSystem::ExportEntryToJson(rapidjson::Value& j_entries, rapidjson::Docu
}
j_entry.AddMember("addonpart_filenames", j_addonfnames, j_doc.GetAllocator());

// Tuneup details
j_entry.AddMember("tuneup_associated_filename", rapidjson::StringRef(entry->tuneup_associated_filename.c_str()), j_doc.GetAllocator());

// Add entry to list
j_entries.PushBack(j_entry, j_doc.GetAllocator());
}
Expand Down Expand Up @@ -1241,8 +1247,10 @@ void CacheSystem::FillTuneupDetailInfo(CacheEntryPtr &entry, TuneupDefPtr& tuneu
entry->description = tuneup_def->description;
entry->categoryid = tuneup_def->category_id;
entry->tuneup_def = tuneup_def; // Needed to generate preview image
entry->tuneup_associated_filename = tuneup_def->filename;

Ogre::StringUtil::toLowerCase(entry->guid);
Ogre::StringUtil::toLowerCase(entry->tuneup_associated_filename);
}

void CacheSystem::LoadAssetPack(CacheEntryPtr& target_entry, Ogre::String const & assetpack_filename)
Expand Down Expand Up @@ -1646,6 +1654,9 @@ CacheEntryPtr CacheSystem::CreateProject(CreateProjectRequest* request)
project_entry->fext = "tuneup"; // Tell modcache what it is.
project_entry->categoryid = CID_Tuneups; // For display in modcache
project_entry->guid = request->cpr_source_entry->guid; // For lookup of tuneups by vehicle GUID.
Ogre::StringUtil::toLowerCase(project_entry->guid);
project_entry->tuneup_associated_filename = request->cpr_source_entry->fname; // For additional filtering of results (GUID marks a family, not individual mod).
Ogre::StringUtil::toLowerCase(project_entry->tuneup_associated_filename);
}
else
{
Expand All @@ -1672,6 +1683,7 @@ CacheEntryPtr CacheSystem::CreateProject(CreateProjectRequest* request)

TuneupDefPtr tuneup = request->cpr_source_actor->getWorkingTuneupDef()->clone();
tuneup->guid = request->cpr_source_entry->guid; // For lookup of tuneups by vehicle GUID.
tuneup->filename = request->cpr_source_entry->fname; // For additional filtering of results (GUID marks a family, not individual mod).
tuneup->name = request->cpr_name;
tuneup->description = request->cpr_description;
tuneup->thumbnail = request->cpr_source_entry->filecachename;
Expand Down Expand Up @@ -2023,7 +2035,7 @@ size_t CacheSystem::Query(CacheQuery& query)
}
}

// Filter by target filename (currently only `addonpart_filenames`); pass items which have no target filenames listed.
// Filter by target filename; pass items which have no target filenames listed.
if (query.cqy_filter_target_filename != "")
{
if (entry->fext == "addonpart"
Expand All @@ -2032,6 +2044,12 @@ size_t CacheSystem::Query(CacheQuery& query)
{
continue;
}
else if (entry->fext == "tuneup"
&& entry->tuneup_associated_filename != ""
&& entry->tuneup_associated_filename != query.cqy_filter_target_filename)
{
continue;
}
}

// Filter by entry type
Expand Down
7 changes: 5 additions & 2 deletions source/main/resources/CacheSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <set>

#define CACHE_FILE "mods.cache"
#define CACHE_FILE_FORMAT 3151 // TBD bump to 14 when merging pull request #3151
#define CACHE_FILE_FORMAT 14
#define CACHE_FILE_FRESHNESS 86400 // 60*60*24 = one day

namespace RoR {
Expand Down Expand Up @@ -74,7 +74,7 @@ class CacheEntry: public RefCountingObject<CacheEntry>

std::time_t addtimestamp; //!< timestamp when this file was added to the cache
Ogre::String uniqueid; //!< file's unique id
Ogre::String guid; //!< global unique id. Type "addonpart" leaves this empty and uses `addonpart_guids`.
Ogre::String guid; //!< global unique id; Type "addonpart" leaves this empty and uses `addonpart_guids`; Always lowercase.
int version; //!< file's version

std::string resource_bundle_type; //!< Archive type recognized by OGRE resource system: 'FileSystem' or 'Zip'
Expand All @@ -98,6 +98,9 @@ class CacheEntry: public RefCountingObject<CacheEntry>
std::set<std::string> addonpart_guids; //!< GUIDs of all vehicles this addonpart is used with.
std::set<std::string> addonpart_filenames; //!< File names of all vehicles this addonpart is used with. If empty, any filename goes.

// following all TUNEUP detail information:
std::string tuneup_associated_filename; //!< Value of 'filename' field in the tuneup file; always lowercase.

// following all TRUCK detail information:
Ogre::String description;
Ogre::String tags;
Expand Down
3 changes: 3 additions & 0 deletions source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ TuneupDefPtr TuneupDef::clone()
ret->author_name = this->author_name ; //std::string
ret->author_id = this->author_id ; //int
ret->category_id = this->category_id ; //CacheCategoryId
ret->filename = this->filename ; //std::string

// addonparts
ret->use_addonparts = this->use_addonparts ;
Expand Down Expand Up @@ -619,6 +620,7 @@ void RoR::TuneupUtil::ParseTuneupAttribute(const std::string& line, TuneupDefPtr
if (attrib == "category_id" && params.size() == 2) { tuneup_def->category_id = (CacheCategoryId)PARSEINT(params[1]); return; }
if (attrib == "guid" && params.size() >= 2) { tuneup_def->guid = params[1]; Ogre::StringUtil::trim(tuneup_def->guid); Ogre::StringUtil::toLowerCase(tuneup_def->guid); return; }
if (attrib == "name" && params.size() >= 2) { tuneup_def->name = params[1]; Ogre::StringUtil::trim(tuneup_def->name); return; }
if (attrib == "filename" && params.size() >= 2) { tuneup_def->filename = params[1]; Ogre::StringUtil::trim(tuneup_def->filename); return; }

// Addonparts and extracted data
if (attrib == "use_addonpart" && params.size() == 2) { tuneup_def->use_addonparts.insert(params[1]); return; }
Expand Down Expand Up @@ -646,6 +648,7 @@ void RoR::TuneupUtil::ExportTuneup(Ogre::DataStreamPtr& stream, TuneupDefPtr& tu
buf << "\tauthor_id = " << tuneup->author_id << "\n";
buf << "\tcategory_id = " << (int)tuneup->category_id << "\n";
buf << "\tguid = " << tuneup->guid << "\n";
buf << "\tfilename = " << tuneup->filename << "\n";
buf << "\n";

// Addonparts and extracted data:
Expand Down
3 changes: 2 additions & 1 deletion source/main/resources/tuneup_fileformat/TuneupFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ struct TuneupDef: public RefCountingObject<TuneupDef>
/// @name General info
/// @{
std::string name;
std::string guid;
std::string guid; //!< target vehicle GUID
std::string filename; //!< target vehicle filename
std::string thumbnail;
std::string description;
std::string author_name;
Expand Down

0 comments on commit 5e77521

Please sign in to comment.