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

Expand and improve randomly-generated music descriptions #34053

Merged
merged 8 commits into from
Oct 1, 2019

Conversation

nornagon
Copy link
Contributor

@nornagon nornagon commented Sep 15, 2019

Summary

SUMMARY: Content "Expand randomly-generated music descriptions"

Purpose of change

The randomly-generated music descriptions were both inconsistent (generating descriptions with syntax errors like "neo -tune"), and were missing a period at the end of the description.

Describe the solution

I've extended the system of replacements in the snippets system so that all snippets can use the <other_snippet_id> syntax, not just NPC text, and then converted the music description logic to use it.

Describe alternatives you've considered

Perhaps this system isn't really necessary, and we'd rather stick to hand-authored lists of snippets rather than more complex generators such as this one.

The rules I've added to the JSON for describing music could be special-cased and written in C++ directly, rather than building a system for expanding text described in JSON.

Instead of reusing the snippets system for this sort of "expanding text", we could introduce a new JSON type ("snippet_generator"?) which could contain all the rules for generating a given type of snippet, like this music generator. This would prevent potential namespace overlap issues, since all the rules would be self-contained, but would prevent re-using generators in multiple places.

These more complex and more fragmented strings might present challenges for translators.

We could expand the system with additional capabilities, such as pluralization, article agreement (a/an), and state tracking, all of which Tracery implements. I've chosen to avoid those and write around these limitations for now to keep things simple for a first cut.

Additional context

Improved music descriptions:
Cataclysm__Dark_Days_Ahead_-_0_D-7603-g1b96ad13c5

@Qrox
Copy link
Contributor

Qrox commented Sep 15, 2019

These more complex and more fragmented strings might present challenges for translators

It would actually make translation relatively easier; previously three fragments were simply concatenated together, disregarding grammar variation among languages...

#symbol#

We already have replacement tags in the form <symbol> in the snippet system. Please build the new system on top of that for better consistency. This also makes sure that the tags are specially handled on Transifex to avoid accidentally changing the tags during translation.

Copy link
Member

@kevingranade kevingranade left a comment

Choose a reason for hiding this comment

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

Please remove the new uses of auto, pervasive auto is an anti pattern that makes the code harder to read.

@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Items / Item Actions / Item Qualities Items and how they work and interact labels Sep 17, 2019
@nornagon
Copy link
Contributor Author

It looks like currently the <> tags are only replaced when they're part of NPC talking or explicitly when generating map snippets for <given_name>, <city> and such, rather than a fully general system. But I agree that we shouldn't have two separate systems for this, so I'll look into consolidating them, using the <> syntax that already exists.

@nornagon
Copy link
Contributor Author

There's still a bit of refactoring opportunity to have the npc talk tag replacement logic re-use the parsing from the snippet logic—e.g. passing a lambda to snippet_library::expand which will be called to handle unknown tags—but this works for now.

@ZhilkinSerg
Copy link
Contributor

Some snippets-related tests are failing now.

@@ -119,7 +141,7 @@ std::string snippet_library::random_from_category( const std::string &cat ) cons
const int index = rng( 0, count - 1 );
auto iter = iters.first;
std::advance( iter, index );
return get( iter->second );
return expand( get( iter->second ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the unit test wants this function to return the unexpanded snippet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the test to check something slightly different, and in the process I discovered:

  1. it was testing two tags that were unused, <drop_weapon> and <catch_up>
  2. there was a snippet using the nonexistent tag, <catch_up>.

I've removed the relevant snippet, and removed the old tags from the test.

As a follow-up, I'd like to write a test that iterates through every snippet and checks that any tags it references are either a special tag (like <yrwp>) or exist in the snippets library. That should prevent any undefined references from sneaking in.

@@ -410,7 +410,6 @@
"Stay with me, <name_g>!",
"Catch up, <name_g>!",
"Keep up!",
"Come on, <catch_up>!",
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it was intended to use <keep_up> here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, but I decided to delete it instead because the capitalization would be wrong, e.g. Come on, Keep up!!

"<let_me_pass>", "<done_mugging>", "<happy>",
"<drop_weapon>", "<swear>", "<lets_talk>",
Copy link
Contributor

Choose a reason for hiding this comment

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

<drop_it> was probably the intended value.

@nornagon
Copy link
Contributor Author

I've updated the PR description to reflect the new code, and I've addressed all review comments. Please take another look when you can :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Items / Item Actions / Item Qualities Items and how they work and interact [JSON] Changes (can be) made in JSON
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants