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

feat: display resolved paths #4270

Merged
merged 8 commits into from
Mar 4, 2024

Conversation

scarf005
Copy link
Member

@scarf005 scarf005 commented Feb 29, 2024

Purpose of change

  • It's very hard to figure out which path exactly cata needs for beginners and devs alike.
  • Make it easier to figure out where is user saves and debug.log
  • Nudge users to use user directory so it's easier to version up game and keep old saves

Describe the solution

  • added a new section, Paths
  • constructed paths using PATH_INFO::<function_name>()
  • added a new file, path_display.{cpp,h}
  • added CLI flag, --paths
  • added CLI help section for --help and --paths
used following script + chatgpt as code generator
import { mapValues } from "$std/collections/map_values.ts"
import { mapEntries } from "$std/collections/map_entries.ts"

const motd_value = "motd_value"
const gfxdir_value = "gfxdir_value"
const config_dir_value = "config_dir_value"
const user_dir_value = "user_dir_value"
const datadir_value = "datadir_value"
const base_path_value = "base_path_value"
const savedir_value = "savedir_value"
const autopickup_value = "autopickup_value"
const options_value = "options_value"
const memorialdir_value = "memorialdir_value"

const values = {
  "PATH_INFO::autopickup()": [autopickup_value],
  "PATH_INFO::base_colors()": [config_dir_value, "base_colors.json"],
  "PATH_INFO::base_path()": [base_path_value],
  "PATH_INFO::colors()": [datadir_value, "raw/", "colors.json"],
  "PATH_INFO::color_templates()": [datadir_value, "raw/", "color_templates/"],
  "PATH_INFO::config_dir()": [config_dir_value],
  "PATH_INFO::custom_colors()": [config_dir_value, "custom_colors.json"],
  "PATH_INFO::datadir()": [datadir_value],
  "PATH_INFO::debug()": [config_dir_value, "debug.log"],
  "PATH_INFO::defaultsounddir()": [datadir_value, "sound"],
  "PATH_INFO::defaulttilejson()": ["tile_config.json"],
  "PATH_INFO::defaulttilepng()": ["tinytile.png"],
  "PATH_INFO::fontconfig()": [datadir_value, "raw/", "fonts.json"],
  "PATH_INFO::user_fontconfig()": [config_dir_value, "fonts.json"],
  "PATH_INFO::fontdir()": [datadir_value, "font/"],
  "PATH_INFO::user_fontdir()": [user_dir_value, "font/"],
  "PATH_INFO::language_defs_file()": [datadir_value, "raw/", "languages.json"],
  "PATH_INFO::graveyarddir()": [user_dir_value, "graveyard/"],
  "PATH_INFO::help()": [datadir_value, "help/", "texts.json"],
  "PATH_INFO::keybindingsdir()": [datadir_value, "raw/keybindings/"],
  "PATH_INFO::main_menu_tips()": [datadir_value, "raw/", "tips.json"],
  "PATH_INFO::lastworld()": [config_dir_value, "lastworld.json"],
  "PATH_INFO::memorialdir()": [memorialdir_value],
  "PATH_INFO::moddir()": [datadir_value, "mods/"],
  "PATH_INFO::options()": [options_value],
  "PATH_INFO::panel_options()": [config_dir_value, "panel_options.json"],
  "PATH_INFO::safemode()": [config_dir_value, "safemode.json"],
  "PATH_INFO::distraction()": [config_dir_value, "distraction.json"],
  "PATH_INFO::savedir()": [savedir_value],
  "PATH_INFO::sokoban()": [datadir_value, "raw/", "sokoban.txt"],
  "PATH_INFO::templatedir()": [user_dir_value, "templates/"],
  "PATH_INFO::user_dir()": [user_dir_value],
  "PATH_INFO::user_gfx()": [user_dir_value, "gfx/"],
  "PATH_INFO::user_keybindings()": [config_dir_value, "keybindings.json"],
  "PATH_INFO::user_moddir()": [user_dir_value, "mods/"],
  "PATH_INFO::user_sound()": [user_dir_value, "sound/"],
  "PATH_INFO::worldoptions()": ["worldoptions.json"],
  "PATH_INFO::crash()": [config_dir_value, "crash.log"],
  "PATH_INFO::tileset_conf()": ["tileset.txt"],
  "PATH_INFO::mods_replacements()": [datadir_value, "mods/", "replacements.json"],
  "PATH_INFO::mods_dev_default()": [datadir_value, "mods/", "default.json"],
  "PATH_INFO::mods_user_default()": [config_dir_value, "default_mods.json"],
  "PATH_INFO::soundpack_conf()": ["soundpack.txt"],
  "PATH_INFO::lua_doc_output()": [config_dir_value, "lua_doc.md"],
  "PATH_INFO::gfxdir()": [gfxdir_value],
  "PATH_INFO::data_sound()": [datadir_value, "sound"],
}

const descs = {
  "PATH_INFO::autopickup()": "autopickup",
  "PATH_INFO::base_colors()": "base colors",
  "PATH_INFO::base_path()": "base path",
  "PATH_INFO::colors()": "colors",
  "PATH_INFO::color_templates()": "color templates",
  "PATH_INFO::config_dir()": "config directory",
  "PATH_INFO::custom_colors()": "custom colors",
  "PATH_INFO::datadir()": "data directory",
  "PATH_INFO::debug()": "debug",
  "PATH_INFO::defaultsounddir()": "default sound directory",
  "PATH_INFO::defaulttilejson()": "default tile JSON",
  "PATH_INFO::defaulttilepng()": "default tile PNG",
  "PATH_INFO::fontconfig()": "font config",
  "PATH_INFO::user_fontconfig()": "user font config",
  "PATH_INFO::fontdir()": "font directory",
  "PATH_INFO::user_fontdir()": "user font directory",
  "PATH_INFO::language_defs_file()": "language definitions file",
  "PATH_INFO::graveyarddir()": "graveyard directory",
  "PATH_INFO::help()": "help",
  "PATH_INFO::keybindingsdir()": "keybindings directory",
  "PATH_INFO::main_menu_tips()": "main menu tips",
  "PATH_INFO::lastworld()": "last world",
  "PATH_INFO::memorialdir()": "memorial directory",
  "PATH_INFO::moddir()": "mods directory",
  "PATH_INFO::options()": "options",
  "PATH_INFO::panel_options()": "panel options",
  "PATH_INFO::safemode()": "safe mode",
  "PATH_INFO::distraction()": "distraction",
  "PATH_INFO::savedir()": "save directory",
  "PATH_INFO::sokoban()": "sokoban",
  "PATH_INFO::templatedir()": "template directory",
  "PATH_INFO::user_dir()": "user directory",
  "PATH_INFO::user_gfx()": "user graphics",
  "PATH_INFO::user_keybindings()": "user keybindings",
  "PATH_INFO::user_moddir()": "user mods directory",
  "PATH_INFO::user_sound()": "user sound",
  "PATH_INFO::worldoptions()": "world options",
  "PATH_INFO::crash()": "crash",
  "PATH_INFO::tileset_conf()": "tileset config",
  "PATH_INFO::mods_replacements()": "mods replacements",
  "PATH_INFO::mods_dev_default()": "mods dev default",
  "PATH_INFO::mods_user_default()": "mods user default",
  "PATH_INFO::soundpack_conf()": "soundpack config",
  "PATH_INFO::lua_doc_output()": "Lua doc output",
  "PATH_INFO::gfxdir()": "graphics directory",
  "PATH_INFO::data_sound()": "data sound",
}

const grouped = Object.groupBy(Object.entries(values), ([_, v]) => v[0])
const sorted = mapValues(
  grouped,
  (xs) => xs?.sort(([_, a], [__, b]) => a.join("/").localeCompare(b.join("/"))).map(([k]) => k),
)
const formatted = mapEntries(
  sorted,
  (
    [k, xs],
  ) => [
    k.replace("_value", "").replace("dir", " Directory"),
    "{\n" + xs?.map((x) => `{ _( "${descs[x]}" ), ${x} },`).join("\n") + "\n}",
  ],
)

console.log(sorted)
console.log(formatted)
for (const [k, v] of Object.entries(formatted)) {
  console.log(`+ path_info( "${k}", ${v} )`)
}

Describe alternatives you've considered

  • also provide the same for CLI flag (--info)?
  • utilize Help section?
  • rename section to Info?
  • resize heights to fill entire screen

Testing

CLI CLI usage
Improved Help Section CLI usage
help section usage
image image
Old Screenshots

Cataclysm: Bright Nights - 0 C-57191-g83ac7d2000db-dirty_01
Cataclysm: Bright Nights - 0 C-57191-g83ac7d2000db-dirty_02
Cataclysm: Bright Nights - 0 C-57191-g83ac7d2000db-dirty_03

@github-actions github-actions bot added the src changes related to source code. label Feb 29, 2024
Copy link
Member Author

@scarf005 scarf005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestions from review with @Coolthulhu in discord (1, 2): move dirs into help/paths

@github-actions github-actions bot added docs PRs releated to docs page JSON related to game datas in JSON format. labels Mar 1, 2024
Copy link
Member

@Coolthulhu Coolthulhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than those, it looks OK, but I'd prefer to get a response before approving.

@scarf005 scarf005 requested a review from Coolthulhu March 3, 2024 22:39
@scarf005 scarf005 merged commit 261705f into cataclysmbnteam:main Mar 4, 2024
13 checks passed
@scarf005 scarf005 deleted the feat-display-dirs branch March 4, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PRs releated to docs page JSON related to game datas in JSON format. src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants