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

Move ascii arts to their own file to avoid bloat #39847

Merged
merged 4 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 33 additions & 0 deletions data/json/ascii_arts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"type": "ascii_art",
"id": "balloon",
"picture": [
" ,,,,,,,,,,,,,",
" .;;;;;;;;;;;;;;;;;;;,.",
" .;;;;;;;;;;;;;;;;;;;;;;;;,",
".;;;;;;;;;;;;;;;;;;;;;;;;;;;;.",
";;;;;@;;;;;;;;;;;;;;;;;;;;;;;;' .............",
";;;;@@;;;;;;;;;;;;;;;;;;;;;;;;'.................",
";;;;@@;;;;;;;;;;;;;;;;;;;;;;;;'...................`",
";;;;@;;;;;;;;;;;;;;;@;;;;;;;'.....................",
" `;;;;;;;;;;;;;;;;;;;@@;;;;;'..................;....",
" `;;;;;;;;;;;;;;;;@@;;;;'....................;;...",
" `;;;;;;;;;;;;;@;;;;'...;.................;;....",
" `;;;;;;;;;;;;' ...;;...............;.....",
" `;;;;;;' ...;;..................",
" ;; ..;...............",
" ` ............",
" ` ......",
" ` ..",
" ` '",
" ` '",
" ` '",
" ` `",
" ` `,",
" `",
" `",
" `."
]
}
]
71 changes: 44 additions & 27 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Use the `Home` key to return to the top.
+ [Other formatting](#other-formatting)
- [Description and content of each JSON file](#description-and-content-of-each-json-file)
* [`data/json/` JSONs](#datajson-jsons)
+ [Ascii_arts](#ascii_arts)
+ [Body_parts](#body_parts)
+ [Bionics](#bionics)
+ [Dreams](#dreams)
Expand Down Expand Up @@ -183,6 +184,7 @@ Here's a quick summary of what each of the JSON files contain, broken down by fo
| Filename | Description
|--- |---
| anatomy.json | a listing of player body parts - do not edit
| ascii_arts.json | ascii arts for item descriptions
| bionics.json | bionics, does NOT include bionic effects
| body_parts.json | an expansion of anatomy.json - do not edit
| clothing_mods.json | definition of clothing mods
Expand Down Expand Up @@ -378,6 +380,47 @@ This section describes each json file and their contents. Each json has their ow

## `data/json/` JSONs

### Ascii_arts

| Identifier | Description
|--- |---
| id | Unique ID. Must be one continuous word, use underscores if necessary.
| picture | Array of string, each entry is a line of an ascii picture and must be less than 42 characters long.
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved

```C++
{
"type": "ascii_art",
"id": "balloon",
"picture": [
" ,,,,,,,,,,,,,",
" .;;;;;;;;;;;;;;;;;;;,.",
" .;;;;;;;;;;;;;;;;;;;;;;;;,",
".;;;;;;;;;;;;;;;;;;;;;;;;;;;;.",
";;;;;@;;;;;;;;;;;;;;;;;;;;;;;;' .............",
";;;;@@;;;;;;;;;;;;;;;;;;;;;;;;'.................",
";;;;@@;;;;;;;;;;;;;;;;;;;;;;;;'...................`",
";;;;@;;;;;;;;;;;;;;;@;;;;;;;'.....................",
" `;;;;;;;;;;;;;;;;;;;@@;;;;;'..................;....",
" `;;;;;;;;;;;;;;;;@@;;;;'....................;;...",
" `;;;;;;;;;;;;;@;;;;'...;.................;;....",
" `;;;;;;;;;;;;' ...;;...............;.....",
" `;;;;;;' ...;;..................",
" ;; ..;...............",
" ` ............",
" ` ......",
" ` ..",
" ` '",
" ` '",
" ` '",
" ` `",
" ` `,",
" `",
" `",
" `."
]
}
```

### Body_parts

| Identifier | Description
Expand Down Expand Up @@ -1513,33 +1556,7 @@ 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.
" `;;;;;;;;;;;;;;;;@@;;;;'....................;;...",
" `;;;;;;;;;;;;;@;;;;'...;.................;;....",
" `;;;;;;;;;;;;' ...;;...............;.....",
" `;;;;;;' ...;;..................",
" ;; ..;...............",
" ` ............",
" ` ......",
" ` ..",
" ` '",
" ` '",
" ` '",
" ` `",
" ` `,",
" `",
" `",
" `."
],
"ascii_picture": "ascii_socks", // Id of the asci_art used for this item
"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
43 changes: 43 additions & 0 deletions src/ascii_art.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "ascii_art.h"

#include "assign.h"
#include "generic_factory.h"

static const int ascii_art_width = 42;

namespace
{
generic_factory<ascii_art> ascii_art_factory( "ascii_art" );
} // namespace

template<>
const ascii_art &string_id<ascii_art>::obj() const
{
return ascii_art_factory.obj( *this );
}

template<>
bool string_id<ascii_art>::is_valid() const
{
return ascii_art_factory.is_valid( *this );
}

void ascii_art::load_ascii_art( const JsonObject &jo, const std::string &src )
{
ascii_art_factory.load( jo, src );
}

void ascii_art::load( const JsonObject &jo, const std::string & )
{
assign( jo, "id", id );

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

20 changes: 20 additions & 0 deletions src/ascii_art.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#ifndef ASCII_ART_H
#define ASCII_ART_H

#include "type_id.h"
#include "json.h"


class ascii_art
{
public:
static void load_ascii_art( const JsonObject &jo, const std::string &src );
void load( const JsonObject &jo, const std::string & );
bool was_loaded;

ascii_art_id id;
std::vector<std::string> picture;
};

#endif
2 changes: 2 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ammo.h"
#include "ammo_effect.h"
#include "anatomy.h"
#include "ascii_art.h"
#include "behavior.h"
#include "bionics.h"
#include "bodypart.h"
Expand Down Expand Up @@ -228,6 +229,7 @@ void DynamicDataLoader::initialize()
add( "hit_range", &Creature::load_hit_range );
add( "scent_type", &scent_type::load_scent_type );
add( "disease_type", &disease_type::load_disease_type );
add( "ascii_art", &ascii_art::load_ascii_art );

// json/colors.json would be listed here, but it's loaded before the others (see init_colors())
// Non Static Function Access
Expand Down
8 changes: 6 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "advanced_inv.h"
#include "ammo.h"
#include "ascii_art.h"
#include "avatar.h"
#include "bionics.h"
#include "bodypart.h"
Expand Down Expand Up @@ -3681,8 +3682,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 ) );
const ascii_art_id art = type->picture_id;
if( art.is_valid() ) {
for( const std::string &line : art->picture ) {
info.push_back( iteminfo( "DESCRIPTION", line ) );
}
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,6 @@ 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 @@ -2211,7 +2204,7 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
assign( jo, "explode_in_fire", def.explode_in_fire );
assign( jo, "insulation", def.insulation_factor );
assign( jo, "solar_efficiency", def.solar_efficiency );
assign( jo, "ascii_picture", def.ascii_picture );
assign( jo, "ascii_picture", def.picture_id );

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

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

// The container it comes in
cata::optional<itype_id> default_container;
Expand Down
3 changes: 3 additions & 0 deletions src/type_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ using efftype_id = string_id<effect_type>;
class scent_type;
using scenttype_id = string_id<scent_type>;

class ascii_art;
using ascii_art_id = string_id<ascii_art>;

class disease_type;
using diseasetype_id = string_id<disease_type>;

Expand Down