Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yudonglin committed Jan 26, 2024
1 parent 04bc15f commit 3780af5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
3 changes: 2 additions & 1 deletion vns-cpp/content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Content::Content(const std::unordered_map<std::string, ContentValueType>& data,
narrator = cast<std::string>(data, "narrator", "");
previous = cast<std::string>(data, "previous", "");
next = ContentNext(
cast<std::unordered_map<std::string, ContentNextValueType>>(data, "next", {{"type", "null"}, {"target", ""}}));
cast<std::unordered_map<
std::string, ContentNextValueType>>(data, "next", {{"type", "default"}, {"target", ""}}));
comments = cast<std::vector<std::string>>(data, "comments", {});
}

Expand Down
17 changes: 7 additions & 10 deletions vns-cpp/contentNext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ nlohmann::json ContentNext::to_json() const
return json_data;
}

bool ContentNext::has_single_target() const
{
return std::holds_alternative<std::string>(target_);
}

bool ContentNext::has_multi_targets() const
{
return !std::holds_alternative<std::string>(target_);
return !has_single_target();
}

std::string ContentNext::get_type() const
Expand All @@ -47,13 +52,5 @@ MultiTargetsType ContentNext::get_targets() const

bool ContentNext::is_null() const
{
if (type_.empty() || type_ == "null")
{
return true;
}
if (std::holds_alternative<std::string>(target_))
{
return std::get<std::string>(target_).empty();
}
return std::get<MultiTargetsType>(target_).empty();
return has_single_target() ? get_target().empty() : get_targets().empty();
}
5 changes: 3 additions & 2 deletions vns-cpp/contentNext.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ class ContentNext
}

ContentNext(const std::unordered_map<std::string, ContentNextValueType>& data) : ContentNext(
std::get<std::string>(data.contains("type") ? data.at("type") : "null"),
std::get<std::string>(data.contains("type") ? data.at("type") : "default"),
data.contains("target") ? data.at("target") : "")
{
}

ContentNext() : ContentNext("null", "")
ContentNext() : ContentNext("default", "")
{
}

[[nodiscard]] std::string get_type() const;
[[nodiscard]] std::string get_target() const;
[[nodiscard]] MultiTargetsType get_targets() const;
[[nodiscard]] bool has_single_target() const;
[[nodiscard]] bool has_multi_targets() const;
[[nodiscard]] bool is_null() const;
[[nodiscard]] std::unordered_map<std::string, ContentNextValueType> to_map() const;
Expand Down
18 changes: 18 additions & 0 deletions vns-cpp/naming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ std::unordered_set<std::string> Naming::GetTags() const
return tags_;
}

// If contains a tag
bool Naming::ContainsTag(const std::string& tag) const
{
return tags_.contains(tag);
}

// Insert a tag
void Naming::InsertTag(const std::string& tag)
{
tags_.insert(tag);
}

// Erase a tag
void Naming::EraseTag(const std::string& tag)
{
tags_.erase(tag);
}

// Check if two Naming objects or a Naming object and a string refer to the same character
bool Naming::Equal(const std::variant<Naming, std::string>& o, const bool must_be_the_same) const
{
Expand Down
3 changes: 3 additions & 0 deletions vns-cpp/naming.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class Naming
[[nodiscard]] std::string ToString() const;
[[nodiscard]] std::string GetName() const;
[[nodiscard]] std::unordered_set<std::string> GetTags() const;
[[nodiscard]] bool ContainsTag(const std::string&) const;
void InsertTag(const std::string&);
void EraseTag(const std::string&);
// Class method to access the database
static std::unordered_map<std::string, std::vector<std::string>>& GetDatabase()
{
Expand Down
20 changes: 10 additions & 10 deletions vns-cpp/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,12 @@ void Processor::convert(int starting_index)
else if (tag == "scene")
{
assert(!previous_.empty());
output_[section_][previous_].next = ContentNext("scene", "");
output_[section_][previous_].next = output_[section_][previous_].next.has_multi_targets()
? ContentNext(
"scene", output_[section_][previous_].next.get_targets())
: ContentNext(
"scene", output_[section_][previous_].next.get_target());
current_data_.background_image = extract_parameter(currentLine);

if (!current_data_.background_image.empty() && current_data_.background_image.length() == 0)
{
current_data_.background_image = nullptr;
}
blocked_ = true;
}
else if (tag == "block")
Expand Down Expand Up @@ -343,14 +342,14 @@ void Processor::convert(int starting_index)
if (std::find(narrator_possible_images.begin(), narrator_possible_images.end(), name_data.GetName()) !=
narrator_possible_images.end())
{
if (name_data.GetTags().contains("silent"))
if (name_data.ContainsTag("silent"))
{
name_data.GetTags().erase("silent");
name_data.EraseTag("silent");
}
}
else
{
name_data.GetTags().insert("silent");
name_data.InsertTag("silent");
}
current_data_.character_images[i] = name_data.ToString();
}
Expand Down Expand Up @@ -402,7 +401,8 @@ void Processor::convert(int starting_index)
}
else
{
output_[section_][previous_].next = ContentNext("default", dialog_associate_key_[line_index_]);
output_[section_][previous_].next = ContentNext(output_[section_][previous_].next.get_type(),
dialog_associate_key_[line_index_]);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion vns-cpp/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void TestNullNext()
const ContentNext test_null_next;
assert(test_null_next.is_null());
assert(!test_null_next.has_multi_targets());
assert(test_null_next.get_type() == "null");
assert(test_null_next.get_type() == "default");
assert(test_null_next.get_target().empty());
}

Expand Down

0 comments on commit 3780af5

Please sign in to comment.