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

Name as an object not supported for some types #38166

Open
snipercup opened this issue Feb 19, 2020 · 5 comments
Open

Name as an object not supported for some types #38166

snipercup opened this issue Feb 19, 2020 · 5 comments
Labels
(P5 - Long-term) Long-term WIP, may stay on the list for a while. Translation I18n

Comments

@snipercup
Copy link
Contributor

Describe the bug

Writing the ammunition_type name as "name": { "str": ".223" },
produces this error:

 DEBUG    : Error: data/mods//dda/../../json/items/ammo_types.json: line 101:13: expecting string but got '{'

    "type": "ammunition_type",
    "id": "22",
    "name": {
            ^
              "str": ".22" },
    "default": "22_lr"
  },


 FUNCTION : bool main_menu::load_character_tab(bool)
 FILE     : src/main_menu.cpp
 LINE     : 1074

The same applies to type 'material' and possibly more. I will reply to this issue if I find more.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Write "name": { "str": ".223" } in ammunition_type
  2. Start a game
  3. Observe error

Expected behavior

Accepting the name as an object

Versions and configuration

  • OS: Windows
    • OS Version: MINGW/CYGWIN/MSYS2 on unknown Windows version
  • Game Version: 0.D-11806-g9df6c1607d [64-bit]
  • Graphics Version: Tiles
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Aftershock [aftershock],
    C.R.I.T Expansion Mod [crt_expansion],
    Magiclysm [magiclysm],
    ]

Additional context

In order to implement #36611 and fix #36110 this issue needs to be solved.
The solution used in #37697 can probably work here too.

@ZhilkinSerg
Copy link
Contributor

It should be easily fixable. Example for material is below:

diff --git a/src/material.cpp b/src/material.cpp
index ffc29bfd67..5fca9e1b94 100644
--- a/src/material.cpp
+++ b/src/material.cpp
@@ -12,7 +12,6 @@
 #include "generic_factory.h"
 #include "item.h"
 #include "json.h"
-#include "translations.h"
 #include "player.h"
 #include "field.h"
 
@@ -39,10 +38,10 @@ const material_type &string_id<material_type>::obj() const
 
 material_type::material_type() :
     id( material_id::NULL_ID() ),
-    _bash_dmg_verb( translate_marker( "damages" ) ),
-    _cut_dmg_verb( translate_marker( "damages" ) )
+    _bash_dmg_verb( to_translation( "damages" ) ),
+    _cut_dmg_verb( to_translation( "damages" ) )
 {
-    _dmg_adj = { translate_marker( "lightly damaged" ), translate_marker( "damaged" ), translate_marker( "very damaged" ), translate_marker( "thoroughly damaged" ) };
+    _dmg_adj = { to_translation( "lightly damaged" ), to_translation( "damaged" ), to_translation( "very damaged" ), to_translation( "thoroughly damaged" ) };
 }
 
 static mat_burn_data load_mat_burn_data( const JsonObject &jsobj )
@@ -87,7 +86,7 @@ void material_type::load( const JsonObject &jsobj, const std::string & )
     mandatory( jsobj, was_loaded, "bash_dmg_verb", _bash_dmg_verb );
     mandatory( jsobj, was_loaded, "cut_dmg_verb", _cut_dmg_verb );
 
-    mandatory( jsobj, was_loaded, "dmg_adj", _dmg_adj, string_reader() );
+    mandatory( jsobj, was_loaded, "dmg_adj", _dmg_adj );
 
     if( jsobj.has_array( "burn_data" ) ) {
         for( JsonObject brn : jsobj.get_array( "burn_data" ) ) {
@@ -145,7 +144,7 @@ material_id material_type::ident() const
 
 std::string material_type::name() const
 {
-    return _( _name );
+    return _name.translated();
 }
 
 cata::optional<itype_id> material_type::salvaged_into() const
@@ -170,12 +169,12 @@ int material_type::cut_resist() const
 
 std::string material_type::bash_dmg_verb() const
 {
-    return _( _bash_dmg_verb );
+    return _bash_dmg_verb.translated();
 }
 
 std::string material_type::cut_dmg_verb() const
 {
-    return _( _cut_dmg_verb );
+    return _cut_dmg_verb.translated();
 }
 
 std::string material_type::dmg_adj( int damage ) const
@@ -186,7 +185,7 @@ std::string material_type::dmg_adj( int damage ) const
     }
 
     // apply bounds checking
-    return _( _dmg_adj[std::min( static_cast<size_t>( damage ), _dmg_adj.size() ) - 1] );
+    return _dmg_adj[std::min( static_cast<size_t>( damage ), _dmg_adj.size() ) - 1].translated();
 }
 
 int material_type::acid_resist() const
diff --git a/src/material.h b/src/material.h
index 8907c816c0..12916c5f87 100644
--- a/src/material.h
+++ b/src/material.h
@@ -13,6 +13,7 @@
 #include "optional.h"
 #include "string_id.h"
 #include "type_id.h"
+#include "translations.h"
 
 class material_type;
 
@@ -32,7 +33,7 @@ class material_type
         bool was_loaded = false;
 
     private:
-        std::string _name;
+        translation _name;
         cata::optional<itype_id> _salvaged_into; // this material turns into this item when salvaged
         itype_id _repaired_with = itype_id( "null" ); // this material can be repaired with this item
         int _bash_resist = 0;                         // negative integers means susceptibility
@@ -51,9 +52,9 @@ class material_type
         bool _soft = false;
         bool _reinforces = false;
 
-        std::string _bash_dmg_verb;
-        std::string _cut_dmg_verb;
-        std::vector<std::string> _dmg_adj;
+        translation _bash_dmg_verb;
+        translation _cut_dmg_verb;
+        std::vector<translation> _dmg_adj;
 
         std::map<vitamin_id, double> _vitamins;
 

@snipercup
Copy link
Contributor Author

Also applies to terrain:
DEBUG : Error: data/mods//dda/../../json/furniture_and_terrain/terrain-manufactured.json: line 180:13: Expected string

"type": "terrain",
"id": "t_atm",
"name": {
        ^
          "str": "ATM" },
"description": "For your banking convenience, this Automated Teller Machine is fully capable of operating autonomously in the event of complete network failure.  You can deposit funds from cash cards and migrate all of 

FUNCTION : bool main_menu::load_character_tab(bool)
FILE : src/main_menu.cpp
LINE : 1074

@snipercup
Copy link
Contributor Author

snipercup commented Mar 3, 2020

Also applies to types:

EXTERNAL_OPTION
overmap_land_use_code
trap
map_extra
recipe_group
scenario
mutation_category
MONSTER_FACTION
furniture
overmap_terrain
construction_category
LOOT_ZONE
faction
technique
vehicle
start_location
monstergroup

@stale
Copy link

stale bot commented Apr 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Please do not 'bump' or comment on this issue unless you are actively working on it. Stale issues, and stale issues that are closed are still considered.

@stale stale bot added the stale Closed for lack of activity, but still valid. label Apr 15, 2020
@ZhilkinSerg ZhilkinSerg added the (P5 - Long-term) Long-term WIP, may stay on the list for a while. label Apr 15, 2020
@stale stale bot removed the stale Closed for lack of activity, but still valid. label Apr 15, 2020
@Night-Pryanik
Copy link
Contributor

Related to #36110.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(P5 - Long-term) Long-term WIP, may stay on the list for a while. Translation I18n
Projects
None yet
Development

No branches or pull requests

3 participants