Skip to content

Commit

Permalink
Effects: Add effect system
Browse files Browse the repository at this point in the history
Now that the annoying stuff is outta the way, fun stuff can be done :)

- Added effect system with old effects recreated + 1 new one
- Changed some defaults and added intensity option for effects
  • Loading branch information
DatCaptainHorse committed Mar 24, 2024
1 parent 4efb1fe commit adbffc1
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 98 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ AlwaysBreakTemplateDeclarations: Yes
IndentRequiresClause: false
# Allow single while loops without braces
AllowShortLoopsOnASingleLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: WithoutElse
1 change: 1 addition & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ target_sources(ChatNotifier PRIVATE FILE_SET CXX_MODULES FILES
opus_decoder.cppm
audio.cppm
twitch.cppm
effect.cppm
notification.cppm
gui.cppm
jsoned.cppm
Expand Down
34 changes: 28 additions & 6 deletions Source/common.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ export auto trim_string(std::string str, const std::string &trim) -> std::string
export auto get_string_between(const std::string &str, const std::string &start,
const std::string &end, const size_t pos = 0) -> std::string {
const auto startPos = str.find(start, pos);
if (startPos == std::string::npos)
return "";
if (startPos == std::string::npos) return "";

const auto endPos = str.find(end, startPos + start.size());
if (endPos == std::string::npos)
return "";
if (endPos == std::string::npos) return "";

return str.substr(startPos + start.size(), endPos - startPos - start.size());
}
Expand All @@ -69,12 +67,36 @@ export auto get_string_between(const std::string &str, const std::string &start,
export auto get_string_until(const std::string &str, const std::string &delim, const size_t pos = 0)
-> std::string {
const auto endPos = str.find(delim, pos);
if (endPos == std::string::npos)
return "";
if (endPos == std::string::npos) return "";

return str.substr(pos, endPos - pos);
}

// Method for getting invidual letters of a string for multi-byte characters
export auto get_letters_mb(const std::string &str) -> std::vector<std::string> {
std::vector<std::string> letters;
const auto *start = str.c_str();
const auto *end = start + str.size();
while (start < end) {
const auto bytes = std::mblen(start, end - start);
if (bytes < 1) break;
letters.emplace_back(start, start + bytes);
start += bytes;
}
return letters;
}

// Returns whether string has letters only
export auto is_letters(const std::string &str) -> bool {
return std::ranges::all_of(str, ::isalpha);
}

// Remaps a value from one range to another
export auto remap_value(const float value, const float inMin, const float inMax, const float outMin,
const float outMax) -> float {
return outMin + (value - inMin) * (outMax - outMin) / (inMax - inMin);
}

// Method for returning a GUID string
export auto generate_guid() -> std::string {
std::random_device rd;
Expand Down
14 changes: 7 additions & 7 deletions Source/config.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export enum class CommandCooldownType { eNone, eGlobal, ePerUser };
// Struct for keeping configs across launches
export struct Config {
float notifAnimationLength = 5.0f;
float notifEffectSpeed = 5.0f;
float notifEffectSpeed = 2.0f;
float notifEffectIntensity = 2.0f;
float notifFontScale = 1.0f;
float globalAudioVolume = 0.75f;
std::vector<std::string> approvedUsers;
Expand All @@ -32,6 +33,7 @@ export struct Config {
JSONed::JSON json;
json["notifAnimationLength"].set<float>(notifAnimationLength);
json["notifEffectSpeed"].set<float>(notifEffectSpeed);
json["notifEffectIntensity"].set<float>(notifEffectIntensity);
json["notifFontScale"].set<float>(notifFontScale);
json["globalAudioVolume"].set<float>(globalAudioVolume);
json["twitchAuthToken"].set<std::string>(twitchAuthToken);
Expand All @@ -44,23 +46,21 @@ export struct Config {
json["ttsVoiceSpeed"].set<float>(ttsVoiceSpeed);
json["approvedUsers"].set<std::vector<std::string>>(approvedUsers);

if (!json.save(get_config_path()))
return Result(1, "Failed to save config");
if (!json.save(get_config_path())) return Result(1, "Failed to save config");

return Result();
}

auto load() -> Result {
// Check if file exists first
if (!std::filesystem::exists(get_config_path()))
return Result();
if (!std::filesystem::exists(get_config_path())) return Result();

JSONed::JSON json;
if (!json.load(get_config_path()))
return Result(1, "Failed to load config");
if (!json.load(get_config_path())) return Result(1, "Failed to load config");

notifAnimationLength = json["notifAnimationLength"].get<float>();
notifEffectSpeed = json["notifEffectSpeed"].get<float>();
notifEffectIntensity = json["notifEffectIntensity"].get<float>();
notifFontScale = json["notifFontScale"].get<float>();
globalAudioVolume = json["globalAudioVolume"].get<float>();
twitchAuthToken = json["twitchAuthToken"].get<std::string>();
Expand Down
Loading

0 comments on commit adbffc1

Please sign in to comment.