Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tobylane
Copy link
Member

@tobylane tobylane commented Jan 9, 2025

Fixes #2742

Describe what the proposed change does

  • Adds a new function to look for a campaign file in the users campaign folder, as well as the Corsixth folder, copied from the getAbsolutePathToLevelFile function above it.
  • Add the users campaign folder to the search in the custom campaigns dialog.

@tobylane tobylane changed the title Campaigndirs Include the users campaign dir in looking for campaigns Jan 9, 2025
@lewri lewri requested a review from Alberth289346 January 9, 2025 21:46
@lewri lewri added the PR:Bugfix label Jan 9, 2025
Comment on lines 708 to 715
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
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Member Author

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)?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

@Alberth289346
Copy link
Contributor

Tried this patch. It fails because I have a mazes directory in the Campaigns directory. Inside the mazes directory are the campaign files.

After copying those into the Campaigns directory, the campaign is found and started.

How to organize campaign files is a different problem from scanning the Campaigns directory, and as such, the patches solves the reported problem.

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.

@Alberth289346
Copy link
Contributor

Apparently, @lewri has previous art with respect to directories in #2209

@tobylane
Copy link
Member Author

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.

self.app.level_dir,
}
local filename = self.app:findFileInDirs(search_paths, level)
errors, result = self:loadMapConfig(filename, base_config, true)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

[Bug] campaigns setting in config file does not work.
3 participants