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 all 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 ) {
info.push_back( iteminfo( "DESCRIPTION", line ) );
}
}
}

std::string item::info( std::vector<iteminfo> &info, const iteminfo_query *parts, int batch ) const
Expand Down
13 changes: 13 additions & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "json.h"
#include "material.h"
#include "options.h"
#include "output.h"
#include "recipe_dictionary.h"
#include "requirements.h"
#include "string_formatter.h"
Expand Down Expand Up @@ -64,6 +65,8 @@ static void npc_implied_flags( itype &item_template );

extern const double MAX_RECOIL;

static const int ascii_art_width = 42;

bool item_is_blacklisted( const std::string &id )
{
return item_blacklist.count( id );
Expand Down Expand Up @@ -414,6 +417,14 @@ void Item_factory::finalize_post( itype &obj )
}
}
}

for( std::string &line : obj.ascii_picture ) {
if( utf8_width( remove_color_tags( line ) ) > ascii_art_width ) {
line = trim_by_length( line, ascii_art_width );
debugmsg( "ascii_picture in %s contains a line too long to be displayed (>%i char).", obj.id,
ascii_art_width );
}
}
}

void Item_factory::finalize()
Expand Down Expand Up @@ -2082,6 +2093,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
9 changes: 7 additions & 2 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ void print_colored_text( const catacurses::window &w, const point &p, nc_color &

void trim_and_print( const catacurses::window &w, const point &begin, int width,
nc_color base_color, const std::string &text )
{
std::string sText = trim_by_length( text, width );
print_colored_text( w, begin, base_color, base_color, sText );
}

std::string trim_by_length( const std::string &text, int width )
{
std::string sText;
if( utf8_width( remove_color_tags( text ) ) > width ) {
Expand Down Expand Up @@ -251,8 +257,7 @@ void trim_and_print( const catacurses::window &w, const point &begin, int width,
} else {
sText = text;
}

print_colored_text( w, begin, base_color, base_color, sText );
return sText;
}

int print_scrollable( const catacurses::window &w, int begin_line, const std::string &text,
Expand Down
1 change: 1 addition & 0 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ inline int fold_and_print_from( const catacurses::window &w, const point &begin,
*/
void trim_and_print( const catacurses::window &w, const point &begin, int width,
nc_color base_color, const std::string &text );
std::string trim_by_length( const std::string &text, int width );
template<typename ...Args>
inline void trim_and_print( const catacurses::window &w, const point &begin,
const int width, const nc_color base_color, const char *const mes, Args &&... args )
Expand Down