-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include the users campaign dir in looking for campaigns #2756
base: master
Are you sure you want to change the base?
Conversation
CorsixTH/Lua/app.lua
Outdated
for _, parent_path in ipairs(paths_to_search) do | ||
local check_path = parent_path .. pathsep .. campaign | ||
local file, _ = io.open(check_path, "rb") | ||
if file then | ||
file:close() | ||
return check_path | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste is oh so convenient, but pretty much always a bad idea. De-duplicating such code afterwards is horribly complicated (try it a few times :) ).
Instead refactor the checking code to its own (private) function, and use it form both spots.
end | ||
end | ||
end | ||
end | ||
table.sort(campaigns, function(a,b) return a.name < b.name end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We get duplicate names if the same campaign exists in both the user and the game directories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is the name from reading the file, it's already possible from two files in the same folder. Should they be given suffixes, like (2)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Numbered suffixes don't help tell them apart, adding the filename to the description of clashes doesn't look good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's tricky.
It gets more complicated if a campaign is being developed and a user downloads several different versions of the same data set.
OpenTTD includes a version number in their extensions, that is available in the data file. Authors often also includes that number in the filenames.
Afaik, they also do checking whether files are the same or not.
But much of it is future work I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, ignore all campaigns with the same name except the first one, dump a log entry with the details, and give a window that says some campaigns were not added due to having duplicated names?
Tried this patch. It fails because I have a After copying those into the How to organize campaign files is a different problem from scanning the This problem should then probably be considered in a next issue, since I am pretty likely not the only person that wants to organize their data differently compared with throwing it all in one directory. |
f8980d0
to
53e58d7
Compare
Refactored the two almost identical functions. Added an information message and detail in console for duplicate campaign names. The UIInformation window is set to be on top, but is below the campaigns dialog. |
53e58d7
to
5a5f510
Compare
self.app.level_dir, | ||
} | ||
local filename = self.app:findFileInDirs(search_paths, level) | ||
errors, result = self:loadMapConfig(filename, base_config, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can load a config from a different spot than the map file. That makes it difficult to predict what files are going to be used.
In my view, if you load a campaign from self.app.campaign_dir
the map and the config should also come from there.
Not sure what should happen if some files are missing, but things should be predictable for a user and level designer.
Also, preferably it should be stable under adding other files (but not sure this is achievable). Eg if a level file was released and it didn't have config, we used file X. If I then add a new version of the level and that one does have a config, then the new version should use that config, but the old one perhaps not, since the entire experience of the level could change.
Fixes #2742
Describe what the proposed change does