-
Notifications
You must be signed in to change notification settings - Fork 0
Add Rgba map to Styles. Use for tints of weapon rounds. #19
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
#pragma once | ||
#include <bave/core/string_hash.hpp> | ||
#include <spaced/services/service.hpp> | ||
#include <spaced/string_map.hpp> | ||
#include <spaced/ui/style.hpp> | ||
#include <unordered_map> | ||
|
||
namespace dj { | ||
class Json; | ||
} | ||
|
||
namespace spaced::ui { | ||
namespace spaced { | ||
struct Styles : IService { | ||
template <typename Type> | ||
using Map = std::unordered_map<std::string, Type, bave::StringHash, std::equal_to<>>; | ||
|
||
Map<ButtonStyle> buttons{}; | ||
Map<ProgressBarStyle> progress_bars{}; | ||
CollectListItemStyle collect_list_item{}; | ||
LoadingScreenStyle loading_screen{}; | ||
StringMap<bave::Rgba> rgbas{}; | ||
StringMap<ui::ButtonStyle> buttons{}; | ||
StringMap<ui::ProgressBarStyle> progress_bars{}; | ||
ui::LoadingScreenStyle loading_screen{}; | ||
|
||
static auto load(dj::Json const& json) -> Styles; | ||
|
||
[[nodiscard]] auto get_button(std::string_view id) const -> ButtonStyle const&; | ||
[[nodiscard]] auto get_progress_bar(std::string_view id) const -> ProgressBarStyle const&; | ||
|
||
[[nodiscard]] auto save() const -> dj::Json; | ||
}; | ||
} // namespace spaced::ui | ||
} // namespace spaced |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
#include <bave/core/string_hash.hpp> | ||
#include <unordered_map> | ||
|
||
namespace spaced { | ||
template <typename ValueType> | ||
class StringMap : public std::unordered_map<std::string, ValueType, bave::StringHash, std::equal_to<>> { | ||
public: | ||
[[nodiscard]] auto get_or(std::string_view const key, ValueType const& fallback) const -> ValueType { | ||
if (auto const it = this->find(key); it != this->end()) { return it->second; } | ||
return fallback; | ||
} | ||
|
||
[[nodiscard]] auto get(std::string_view const key) const -> ValueType | ||
requires(std::is_default_constructible_v<ValueType>) | ||
{ | ||
return get_or(key, ValueType{}); | ||
} | ||
|
||
[[nodiscard]] auto operator[](std::string_view const key) const -> ValueType | ||
requires(std::is_default_constructible_v<ValueType>) | ||
{ | ||
return get(key); | ||
} | ||
}; | ||
} // namespace spaced |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why pass a reference to
services
here, and in all the other places? could you also have someServiceLocator
with services and include it in any needed.cpp
s? if not, why not?Uh oh!
There was an error while loading. Please reload this page.
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.
Services
is a service locator, it's just not globally accessible / a singleton. It has its own lifetime and ownership, which supercedes all the services it owns, thereby also giving them explicit lifetime and ownership. Globals, especially singletons, take away both of these very important aspects in C++.The rest of your thinking is spot on: instead of passing dozens of different references in various constructors (which would be most explicit and correct, but too cumbersome and volatile), we design commonly referenced items as services, initialized by the game driver (
Spaced
).