Skip to content

Commit

Permalink
Assorted minor fixes (clang-format.sh shebang, parse national foci sc…
Browse files Browse the repository at this point in the history
…ripts, factor song chance, update openvic-dataloader)
  • Loading branch information
Hop311 committed Aug 13, 2024
1 parent 9f9c584 commit 7e05aac
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion clang-format.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/usr/bin/env bash
#!/usr/bin/env bash

echo "\n\nFormatting openvic-simulation with clang-format:\n"
find ./src/ -iname *.hpp -o -iname *.cpp | xargs clang-format --verbose -i
Expand Down
5 changes: 3 additions & 2 deletions src/openvic-simulation/dataloader/Dataloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ bool Dataloader::_load_song_chances(DefinitionManager& definition_manager) {
bool ret = true;
SongChanceManager& song_chance_manager = definition_manager.get_song_chance_manager();

if(path.empty()) {
if (path.empty()) {
Logger::info("No Songs.txt file to load");
song_chance_manager.lock_song_chances();
return true;
Expand Down Expand Up @@ -1096,7 +1096,7 @@ bool Dataloader::load_defines(DefinitionManager& definition_manager) {
Logger::error("Failed to load diplomatic actions!");
ret = false;
}
if(!definition_manager.get_script_manager().get_condition_manager().setup_conditions(definition_manager)) {
if (!definition_manager.get_script_manager().get_condition_manager().setup_conditions(definition_manager)) {
Logger::error("Failed to set up conditions!");
ret = false;
}
Expand Down Expand Up @@ -1131,6 +1131,7 @@ bool Dataloader::parse_scripts(DefinitionManager& definition_manager) const {
PARSE_SCRIPTS("decision", definition_manager.get_decision_manager());
PARSE_SCRIPTS("event", definition_manager.get_event_manager());
PARSE_SCRIPTS("song chance", definition_manager.get_song_chance_manager());
PARSE_SCRIPTS("national focus", definition_manager.get_politics_manager().get_national_focus_manager());
return ret;
}

Expand Down
6 changes: 2 additions & 4 deletions src/openvic-simulation/interface/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,10 @@ bool Text::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map, UIManag
"maxWidth", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(max_size.x)),
"maxHeight", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(max_size.y)),
"borderSize", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(border_size)),
"textureFile", ZERO_OR_ONE, expect_string(assign_variable_callback_string(texture_file), true),

"fixedsize", ZERO_OR_ONE, success_callback,
"allwaystransparent", ZERO_OR_ONE, success_callback,

// Add warning about redundant key?
"textureFile", ZERO_OR_ONE, success_callback
"allwaystransparent", ZERO_OR_ONE, success_callback
);
return ret;
}
Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/interface/GUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ namespace OpenVic::GUI {
GFX::Font const* PROPERTY(font);
fvec2_t PROPERTY(max_size); /* Defines keys: maxWidth, maxHeight */
fvec2_t PROPERTY(border_size);
std::string PROPERTY(texture_file);

// TODO - fixedsize, textureFile
// TODO - fixedsize

protected:
Text();
Expand Down
1 change: 0 additions & 1 deletion src/openvic-simulation/military/UnitInstanceGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ UnitInstanceGroupBranched<UnitType::branch_t::NAVAL>::UnitInstanceGroupBranched(
std::vector<ShipInstance*>&& new_units
) : UnitInstanceGroup { new_name, std::move(new_units) } {}


fixed_point_t UnitInstanceGroupBranched<UnitType::branch_t::NAVAL>::get_total_consumed_supply() const {
fixed_point_t total_consumed_supply = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/military/UnitType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool UnitTypeManager::load_unit_type_file(
) {
using namespace std::string_view_literals;
auto type_symbol = parser.find_intern("type"sv);
if(!type_symbol) {
if (!type_symbol) {
Logger::error("type could not be interned.");
}

Expand Down
18 changes: 8 additions & 10 deletions src/openvic-simulation/misc/SongChance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
using namespace OpenVic;
using namespace OpenVic::NodeTools;

SongChance::SongChance(size_t new_index, std::string_view new_filename, ConditionalWeight&& new_chance):
HasIdentifier { std::to_string(new_index) },
file_name { new_filename },
chance { std::move(new_chance) }
{}
SongChance::SongChance(
size_t new_index, std::string_view new_filename, ConditionalWeight&& new_chance
) : HasIdentifier { std::to_string(new_index) }, file_name { new_filename }, chance { std::move(new_chance) } {}

bool SongChance::parse_scripts(DefinitionManager const& definition_manager) {
return chance.parse_scripts(definition_manager);
}

bool SongChanceManager::load_songs_file(ast::NodeCPtr root) {
bool ret = true;
bool ret = true;

ret &= expect_dictionary_reserve_length(
song_chances,
Expand All @@ -28,15 +26,15 @@ bool SongChanceManager::load_songs_file(ast::NodeCPtr root) {

bool ret = expect_dictionary_keys(
"name", ONE_EXACTLY, expect_string(assign_variable_callback(name)),
"chance", ONE_EXACTLY, chance.expect_conditional_weight(ConditionalWeight::BASE)
"chance", ONE_EXACTLY, chance.expect_conditional_weight(ConditionalWeight::FACTOR)
)(value);

ret &= song_chances.add_item({song_chances.size(), name, std::move(chance) });
ret &= song_chances.add_item({ song_chances.size(), name, std::move(chance) });
return ret;
}
)(root);

if(song_chances.size() == 0) {
if (song_chances.size() == 0) {
Logger::error("No songs found in Songs.txt");
return false;
}
Expand All @@ -50,4 +48,4 @@ bool SongChanceManager::parse_scripts(DefinitionManager const& definition_manage
ret &= songChance.parse_scripts(definition_manager);
}
return ret;
}
}
12 changes: 8 additions & 4 deletions src/openvic-simulation/misc/SongChance.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#pragma once

#include <openvic-simulation/types/IdentifierRegistry.hpp>
#include <openvic-simulation/scripts/ConditionalWeight.hpp>
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/scripts/ConditionalWeight.hpp"

namespace OpenVic {
/*For music/Songs.txt if it exists*/
struct SongChanceManager;

struct SongChance : HasIdentifier {
private:
friend struct SongChanceManager;

private:
std::string PROPERTY(file_name);
ConditionalWeight PROPERTY(chance);

SongChance(size_t new_index, std::string_view new_filename, ConditionalWeight&& new_chance);

bool parse_scripts(DefinitionManager const& definition_manager);

public:
SongChance(SongChance&&) = default;
};
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/misc/SoundEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool SoundEffectManager::_load_sound_define(std::string_view sfx_identifier, ast
Logger::error("Invalid sound identifier - empty!");
return false;
}
if(file.empty()) {
if (file.empty()) {
Logger::error("Invalid sound file name - empty!");
return false;
}
Expand All @@ -35,4 +35,4 @@ bool SoundEffectManager::load_sound_defines_file(ast::NodeCPtr root) {
return _load_sound_define(key,value);
}
)(root);
}
}
18 changes: 10 additions & 8 deletions src/openvic-simulation/misc/SoundEffect.hpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
#pragma once

#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>
#include <openvic-simulation/types/IdentifierRegistry.hpp>
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"

namespace OpenVic {
/*For interface/Sound.sfx */
struct SoundEffectManager;

struct SoundEffect : HasIdentifier {
private:
friend struct SoundEffectManager;

private:
std::string PROPERTY(file);
fixed_point_t PROPERTY(volume);

SoundEffect(std::string_view new_identifier, std::string_view new_file, fixed_point_t new_volume);

public:
SoundEffect(SoundEffect&&) = default;
};

struct SoundEffectManager {

private:
IdentifierRegistry<SoundEffect> IDENTIFIER_REGISTRY(sound_effect);
IdentifierRegistry<SoundEffect> IDENTIFIER_REGISTRY(sound_effect);
bool _load_sound_define(std::string_view sfx_identifier, ast::NodeCPtr root);

public:
bool load_sound_defines_file(ast::NodeCPtr root);
};
}
}

0 comments on commit 7e05aac

Please sign in to comment.