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

Bionic UI: power display in kJ, J, mJ #34753

Merged
merged 2 commits into from
Oct 18, 2019
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
2 changes: 1 addition & 1 deletion data/json/bionics.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@
"id": "bio_night",
"type": "bionic",
"name": "Artificial Night Generator",
"description": "When active, this bionic eliminates all light within a 15 tile radius through destructive interference.",
"description": "When active, this bionic eliminates all light within a 2 tile radius through destructive interference.",
"occupied_bodyparts": [ [ "TORSO", 16 ] ],
"flags": [ "BIONIC_TOGGLED" ],
"act_cost": "9 kJ",
Expand Down
12 changes: 6 additions & 6 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ static std::string build_bionic_poweronly_string( const bionic &bio )
std::vector<std::string> properties;

if( bio_data.power_activate > 0_kJ ) {
properties.push_back( string_format( _( "%d kJ act" ),
units::to_kilojoule( bio_data.power_activate ) ) );
properties.push_back( string_format( _( "%s act" ),
units::display( bio_data.power_activate ) ) );
}
if( bio_data.power_deactivate > 0_kJ ) {
properties.push_back( string_format( _( "%d kJ deact" ),
units::to_kilojoule( bio_data.power_deactivate ) ) );
properties.push_back( string_format( _( "%s deact" ),
units::display( bio_data.power_deactivate ) ) );
}
if( bio_data.charge_time > 0 && bio_data.power_over_time > 0_kJ ) {
properties.push_back( bio_data.charge_time == 1
? string_format( _( "%d kJ/turn" ), units::to_kilojoule( bio_data.power_over_time ) )
: string_format( _( "%d kJ/%d turns" ), units::to_kilojoule( bio_data.power_over_time ),
? string_format( _( "%s/turn" ), units::display( bio_data.power_over_time ) )
: string_format( _( "%s/%d turns" ), units::display( bio_data.power_over_time ),
bio_data.charge_time ) );
}
if( bio_data.toggled ) {
Expand Down
14 changes: 14 additions & 0 deletions src/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,20 @@ inline std::ostream &operator<<( std::ostream &o, const quantity<value_type, tag
return o << v.value() << tag_type{};
}

inline const std::string display( const units::energy v )
{
const int kj = units::to_kilojoule( v );
const int j = units::to_joule( v );
if( kj >= 1 && float( j ) / kj == 1000 ) { // at least 1 kJ and there is no fraction
return string_format( "%d kJ", kj );
RDru marked this conversation as resolved.
Show resolved Hide resolved
}
const int mj = units::to_millijoule( v );
if( j >= 1 && float( mj ) / j == 1000 ) { // at least 1 J and there is no fraction
return string_format( "%d J", j );
}
return string_format( "%d mJ", mj );
}

} // namespace units

// Implicitly converted to volume, which has int as value_type!
Expand Down