Skip to content

Commit 5e77521

Browse files
committed
Tuning: added matching tuneups by filename (on top of GUID)
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.
1 parent 7e9d4bb commit 5e77521

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

source/main/gui/panels/GUI_TopMenubar.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2496,6 +2496,7 @@ void TopMenubar::RefreshTuningMenu()
24962496

24972497
tuning_saves.cqy_filter_type = LT_Tuneup;
24982498
tuning_saves.cqy_filter_guid = tuning_actor->getUsedActorEntry()->guid;
2499+
tuning_saves.cqy_filter_target_filename = tuning_actor->getTruckFileName();
24992500
tuning_saves.cqy_filter_category_id = CID_Tuneups; // Exclude auto-generated entries
25002501
tuning_saves.resetResults();
25012502
App::GetCacheSystem()->Query(tuning_saves);

source/main/resources/CacheSystem.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ void CacheSystem::ImportEntryFromJson(rapidjson::Value& j_entry, CacheEntryPtr &
340340
{
341341
out_entry->addonpart_filenames.insert(j_addonfname.GetString());
342342
}
343+
344+
// Tuneup details
345+
out_entry->tuneup_associated_filename = j_entry["tuneup_associated_filename"].GetString();
343346
}
344347

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

628+
// Tuneup details
629+
j_entry.AddMember("tuneup_associated_filename", rapidjson::StringRef(entry->tuneup_associated_filename.c_str()), j_doc.GetAllocator());
630+
625631
// Add entry to list
626632
j_entries.PushBack(j_entry, j_doc.GetAllocator());
627633
}
@@ -1241,8 +1247,10 @@ void CacheSystem::FillTuneupDetailInfo(CacheEntryPtr &entry, TuneupDefPtr& tuneu
12411247
entry->description = tuneup_def->description;
12421248
entry->categoryid = tuneup_def->category_id;
12431249
entry->tuneup_def = tuneup_def; // Needed to generate preview image
1250+
entry->tuneup_associated_filename = tuneup_def->filename;
12441251

12451252
Ogre::StringUtil::toLowerCase(entry->guid);
1253+
Ogre::StringUtil::toLowerCase(entry->tuneup_associated_filename);
12461254
}
12471255

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

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

2026-
// Filter by target filename (currently only `addonpart_filenames`); pass items which have no target filenames listed.
2038+
// Filter by target filename; pass items which have no target filenames listed.
20272039
if (query.cqy_filter_target_filename != "")
20282040
{
20292041
if (entry->fext == "addonpart"
@@ -2032,6 +2044,12 @@ size_t CacheSystem::Query(CacheQuery& query)
20322044
{
20332045
continue;
20342046
}
2047+
else if (entry->fext == "tuneup"
2048+
&& entry->tuneup_associated_filename != ""
2049+
&& entry->tuneup_associated_filename != query.cqy_filter_target_filename)
2050+
{
2051+
continue;
2052+
}
20352053
}
20362054

20372055
// Filter by entry type

source/main/resources/CacheSystem.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <set>
4040

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

4545
namespace RoR {
@@ -74,7 +74,7 @@ class CacheEntry: public RefCountingObject<CacheEntry>
7474

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

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

101+
// following all TUNEUP detail information:
102+
std::string tuneup_associated_filename; //!< Value of 'filename' field in the tuneup file; always lowercase.
103+
101104
// following all TRUCK detail information:
102105
Ogre::String description;
103106
Ogre::String tags;

source/main/resources/tuneup_fileformat/TuneupFileFormat.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ TuneupDefPtr TuneupDef::clone()
4747
ret->author_name = this->author_name ; //std::string
4848
ret->author_id = this->author_id ; //int
4949
ret->category_id = this->category_id ; //CacheCategoryId
50+
ret->filename = this->filename ; //std::string
5051

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

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

651654
// Addonparts and extracted data:

source/main/resources/tuneup_fileformat/TuneupFileFormat.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ struct TuneupDef: public RefCountingObject<TuneupDef>
9595
/// @name General info
9696
/// @{
9797
std::string name;
98-
std::string guid;
98+
std::string guid; //!< target vehicle GUID
99+
std::string filename; //!< target vehicle filename
99100
std::string thumbnail;
100101
std::string description;
101102
std::string author_name;

0 commit comments

Comments
 (0)