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

Add the option to display ascii art in item description #37598

Merged
merged 11 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,33 @@ See also VEHICLE_JSON.md
"symbol": "[", // The item symbol as it appears on the map. Must be a Unicode string exactly 1 console cell width.
"looks_like": "rag", // hint to tilesets if this item has no tile, use the looks_like tile
"description": "Socks. Put 'em on your feet.", // Description of the item
"ascii_picture": [
" ,,,,,,,,,,,,,",
" .;;;;;;;;;;;;;;;;;;;,.",
" .;;;;;;;;;;;;;;;;;;;;;;;;,",
".;;;;;;;;;;;;;;;;;;;;;;;;;;;;.",
";;;;;@;;;;;;;;;;;;;;;;;;;;;;;;' .............",
";;;;@@;;;;;;;;;;;;;;;;;;;;;;;;'.................",
";;;;@@;;;;;;;;;;;;;;;;;;;;;;;;'...................`",
";;;;@;;;;;;;;;;;;;;;@;;;;;;;'.....................",
" `;;;;;;;;;;;;;;;;;;;@@;;;;;'..................;....", // Ascii art that will be displayed at the bottom of the item description. Array of string with each element being a line of the picture. Lines longer than 42 characters won't display properly.
" `;;;;;;;;;;;;;;;;@@;;;;'....................;;...",
" `;;;;;;;;;;;;;@;;;;'...;.................;;....",
" `;;;;;;;;;;;;' ...;;...............;.....",
" `;;;;;;' ...;;..................",
" ;; ..;...............",
" ` ............",
" ` ......",
" ` ..",
" ` '",
" ` '",
" ` '",
" ` `",
" ` `,",
" `",
" `",
" `."
],
Copy link
Contributor

Choose a reason for hiding this comment

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

While an example is good, I definitely think we want to mention what the typical line widths are in the common interfaces so that artists don't have to guess at whether or not their design will fit.

"phase": "solid", // (Optional, default = "solid") What phase it is
"weight": "350 g", // Weight, weight in grams, mg and kg can be used - "50 mg", "5 g" or "5 kg". For stackable items (ammo, comestibles) this is the weight per charge.
"volume": "250 ml", // Volume, volume in ml and L can be used - "50 ml" or "2 L". For stackable items (ammo, comestibles) this is the volume of stack_size charges.
Expand Down
5 changes: 5 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3331,6 +3331,11 @@ void item::final_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
}
}
}
if( get_option<bool>( "ENABLE_ASCII_ART_ITEM" ) ) {
for( const std::string line : type->ascii_picture ) {
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
info.push_back( iteminfo( "DESCRIPTION", line ) );
}
}
}

std::string item::info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch ) const
Expand Down
14 changes: 14 additions & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,18 @@ void Item_factory::finalize_post( itype &obj )
}
}
}

if( !obj.ascii_picture.empty() ) {
std::vector<std::string> tmp_ascii_pic;
for( std::string line : obj.ascii_picture ) {
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
if( line.length() > 42 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't really use neither length nor substr here. These functions consider string length in terms of bytes, but the string is actually in UTF-8 (multi-byte encoding) and can also contain tags. Use utf8_width and remove_color_tags to get the actual "printable" length of the string.

42 is a magic number (quite famous, but still magic). Use a named constant instead.

line = line.substr( 0, 42 );
debugmsg( "ascii_picture in %s contains a line too long to be displayed (>42 char).", obj.id );
}
tmp_ascii_pic.emplace_back( line );
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
}
obj.ascii_picture = tmp_ascii_pic;
}
}

void Item_factory::finalize()
Expand Down Expand Up @@ -2082,6 +2094,8 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
assign( jo, "magazine_well", def.magazine_well );
assign( jo, "explode_in_fire", def.explode_in_fire );
assign( jo, "insulation", def.insulation_factor );
assign( jo, "ascii_picture", def.ascii_picture );


if( jo.has_member( "thrown_damage" ) ) {
def.thrown_damage = load_damage_instance( jo.get_array( "thrown_damage" ) );
Expand Down
1 change: 1 addition & 0 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ struct itype {

std::string snippet_category;
translation description; // Flavor text
std::vector<std::string> ascii_picture;

// The container it comes in
cata::optional<itype_id> default_container;
Expand Down
6 changes: 6 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,12 @@ void options_manager::add_options_graphics()
true, COPT_CURSES_HIDE
);

add( "ENABLE_ASCII_ART_ITEM", "graphics",
translate_marker( "Enable ASCII art in item descriptions" ),
translate_marker( "When available item description will show a picture of the item in ascii art." ),
true, COPT_NO_HIDE
);

add_empty_line();

add( "USE_TILES", "graphics", translate_marker( "Use tiles" ),
Expand Down