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

Runtime config #174

Merged
merged 13 commits into from
May 2, 2024
Merged

Conversation

Dragonfly911117
Copy link
Contributor

@Dragonfly911117 Dragonfly911117 commented Apr 9, 2024

Implement #153

How to Use

To use, place a config.json file either in the current directory (.) or the parent directory (..). If both directories contain the file, the one in the current directory will be read.

Example directory structure:

├── build/
│   ├── YOUR_GAME
│   └── config.json <- place here
└── config.json <- or here

The config.json file can contain any number of configurations, each in the following format:

{
  "title": "<string, default is 'Practice-Tools-for-Simple-Design'>",
  "window_pos_x": <int, default is SDL_WINDOWPOS_UNDEFINED (wherever the OS places the window)>,
  "window_pos_y": <int, default is SDL_WINDOWPOS_UNDEFINED (wherever the OS places the window)>,
  "window_width": <int, default is 1280>,
  "window_height": <int, default is 720>,
  "default_log_level": <int in range [0, 5], default is 2 (Util::Logger::Level::INFO)>,
  "fps_cap": <int, default is 60>
}

If a key is not present in the config.json, the default value will be used.

@Dragonfly911117 Dragonfly911117 added bug Something isn't working enhancement New feature or request breaking breaking change labels Apr 9, 2024
@Dragonfly911117 Dragonfly911117 linked an issue Apr 9, 2024 that may be closed by this pull request
1 task

This comment was marked as resolved.

CMakeLists.txt Outdated Show resolved Hide resolved
src/Util/Text.cpp Outdated Show resolved Hide resolved

This comment was marked as resolved.

include/Util/Config.hpp Outdated Show resolved Hide resolved

This comment was marked as resolved.

@ntut-rick ntut-rick self-requested a review April 25, 2024 09:35
@Dragonfly911117 Dragonfly911117 changed the title Runtime config and small bug fix Runtime config Apr 25, 2024
@Dragonfly911117 Dragonfly911117 removed the bug Something isn't working label Apr 28, 2024
@Dragonfly911117 Dragonfly911117 marked this pull request as ready for review April 28, 2024 08:40

This comment was marked as resolved.

Copy link
Contributor

@onon1101 onon1101 left a comment

Choose a reason for hiding this comment

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

不曉得是不是能從 std::string 改成 C++17 的 std::string_view, 可能會對記憶體分配好一點?

src/config.cpp Outdated Show resolved Hide resolved
include/config.hpp Outdated Show resolved Hide resolved
src/config.cpp Outdated Show resolved Hide resolved
@onon1101
Copy link
Contributor

並且在其他的地方以 data() 等方式存取, (具體可能要看 cpp 的文件)

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

include/config.hpp Show resolved Hide resolved
Copy link

sonarcloud bot commented May 2, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

github-actions bot commented May 2, 2024

clang-tidy review says "All clean, LGTM! 👍"

@NOOBDY NOOBDY merged commit e9db998 into ntut-open-source-club:main May 2, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking breaking change enhancement New feature or request
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

read config at runtime
4 participants