Skip to content

Commit

Permalink
Update WeaponStats TGUI (#386)
Browse files Browse the repository at this point in the history
Co-authored-by: Drathek <[email protected]>
Co-authored-by: Vile Beggar <[email protected]>
  • Loading branch information
3 people committed Aug 18, 2024
1 parent 76d3bb5 commit 36ffd34
Show file tree
Hide file tree
Showing 95 changed files with 85 additions and 93 deletions.
57 changes: 21 additions & 36 deletions code/modules/asset_cache/asset_list_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,9 @@
"nano/templates/",
)

/datum/asset/directory/nanoui/weapons
common_dirs = list(
"nano/images/weapons/",
)

uncommon_dirs = list()

/datum/asset/directory/nanoui/weapons/send(client)
if(!client)
log_debug("Warning! Tried to send nanoui weapon data with a null client! (asset_list_items.dm line 93)")
return
SSassets.transport.send_assets(client, common)


/datum/asset/simple/nanoui_images
keep_local_name = TRUE

assets = list(
"auto.png" = 'nano/images/weapons/auto.png',
"burst.png" = 'nano/images/weapons/burst.png',
"single.png" = 'nano/images/weapons/single.png',
"disabled_automatic.png" = 'nano/images/weapons/disabled_automatic.png',
"disabled_burst.png" = 'nano/images/weapons/disabled_burst.png',
"disabled_single.png" = 'nano/images/weapons/disabled_single.png',
"no_name.png" = 'nano/images/weapons/no_name.png',
)

var/list/common_dirs = list(
"nano/images/",
)
Expand Down Expand Up @@ -384,9 +360,29 @@
name = "gunlineart"

/datum/asset/spritesheet/gun_lineart/register()
InsertAll("", 'icons/obj/items/weapons/guns/lineart.dmi')
var/icon_file = 'icons/obj/items/weapons/guns/lineart.dmi'
InsertAll("", icon_file)

for(var/obj/item/weapon/gun/current_gun as anything in subtypesof(/obj/item/weapon/gun))
if(isnull(initial(current_gun.icon_state)))
continue
if(initial(current_gun.flags_gun_features) & GUN_UNUSUAL_DESIGN)
continue // These don't have a way to inspect weapon stats
var/obj/item/weapon/gun/temp_gun = new current_gun
var/icon_state = temp_gun.base_gun_icon // base_gun_icon is set in Initialize generally
qdel(temp_gun)
if(icon_state && isnull(sprites[icon_state]))
// upgrade this to a stack_trace once all guns have a lineart and we want to lint against that
log_debug("[current_gun] does not have a valid lineart icon state, icon=[icon_file], icon_state=[json_encode(icon_state)]")

..()

/datum/asset/spritesheet/gun_lineart_modes
name = "gunlineartmodes"

/datum/asset/spritesheet/gun_lineart_modes/register()
InsertAll("", 'icons/obj/items/weapons/guns/lineart_modes.dmi')
..()

/datum/asset/simple/orbit
assets = list(
Expand All @@ -400,17 +396,6 @@
"ntosradarpointerS.png" = 'icons/images/ui_images/ntosradar_pointer_S.png'
)

/datum/asset/simple/firemodes
assets = list(
"auto.png" = 'html/images/auto.png',
"disabled_auto.png" = 'html/images/disabled_automatic.png',
"burst.png" = 'html/images/burst.png',
"disabled_burst.png" = 'html/images/disabled_burst.png',
"single.png" = 'html/images/single.png',
"disabled_single.png" = 'html/images/disabled_single.png',
)


/datum/asset/simple/particle_editor
assets = list(
"motion" = 'icons/images/ui_images/particle_editor/motion.png',
Expand Down
12 changes: 9 additions & 3 deletions code/modules/autowiki/pages/guns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@

var/list/gun_to_ammo = list()

for(var/obj/item/ammo_magazine/typepath as anything in subtypesof(/obj/item/ammo_magazine) - subtypesof(/obj/item/ammo_magazine/internal))
for(var/obj/item/ammo_magazine/typepath as anything in subtypesof(/obj/item/ammo_magazine) - typesof(/obj/item/ammo_magazine/internal))
if(isnull(initial(typepath.icon_state)))
continue // Skip mags with no icon_state (e.g. base types)
LAZYADD(gun_to_ammo[initial(typepath.gun_type)], typepath)

for(var/typepath in sort_list(subtypesof(/obj/item/weapon/gun), GLOBAL_PROC_REF(cmp_typepaths_asc)))
var/obj/item/weapon/gun/generating_gun = new typepath()
var/obj/item/weapon/gun/generating_gun = typepath
if(isnull(initial(generating_gun.icon_state)))
continue // Skip guns with no icon_state (e.g. base types)

generating_gun = new typepath()
var/filename = SANITIZE_FILENAME(escape_value(format_text(generating_gun.name)))

var/list/gun_data = generating_gun.ui_data()

var/list/valid_mag_types = list()
Expand Down Expand Up @@ -70,6 +74,8 @@

var/list/attachments_by_slot = list()
for(var/obj/item/attachable/attachment_typepath as anything in generating_gun.attachable_allowed)
if(isnull(initial(attachment_typepath.icon_state)))
continue // Skip attachments with no icon_state (e.g. base types)
LAZYADD(attachments_by_slot[capitalize(initial(attachment_typepath.slot))], attachment_typepath)

var/attachments = ""
Expand Down
29 changes: 9 additions & 20 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,13 @@ As sniper rifles have both and weapon mods can change them as well. ..() deals w
gun_recoil = recoil_buildup

var/penetration = 0
var/armor_punch = 0
var/accuracy = 0
var/min_accuracy = 0
var/max_range = 0
var/effective_range = 0
var/scatter = 0
var/list/damage_armor_profile_xeno = list()
var/list/damage_armor_profile_marine = list()
var/list/damage_armor_profile_armorbreak = list()
var/list/damage_armor_profile_headers = list()

var/datum/ammo/in_ammo
Expand All @@ -638,35 +637,26 @@ As sniper rifles have both and weapon mods can change them as well. ..() deals w
falloff = in_ammo.damage_falloff * damage_falloff_mult

penetration = in_ammo.penetration
armor_punch = in_ammo.damage_armor_punch

accuracy = in_ammo.accurate_range

min_accuracy = in_ammo.accurate_range_min

max_range = in_ammo.max_range
effective_range = in_ammo.effective_range_max
scatter = in_ammo.scatter

for(var/i = 0; i<=CODEX_ARMOR_MAX; i+=CODEX_ARMOR_STEP)
damage_armor_profile_headers.Add(i)
damage_armor_profile_marine.Add(round(armor_damage_reduction(GLOB.marine_ranged_stats, damage, i, penetration)))
damage_armor_profile_xeno.Add(round(armor_damage_reduction(GLOB.xeno_ranged_stats, damage, i, penetration)))
if(!GLOB.xeno_general.armor_ignore_integrity)
if(i != 0)
damage_armor_profile_armorbreak.Add("[round(armor_break_calculation(GLOB.xeno_ranged_stats, damage, i, penetration, in_ammo.pen_armor_punch, armor_punch)/i)]%")
else
damage_armor_profile_armorbreak.Add("N/A")
damage_armor_profile_marine.Add(floor(armor_damage_reduction(GLOB.marine_ranged_stats, damage, i, penetration)))
damage_armor_profile_xeno.Add(floor(armor_damage_reduction(GLOB.xeno_ranged_stats, damage, i, penetration)))

var/rpm = max(fire_delay, 1)
var/burst_rpm = max((fire_delay * 1.5 + (burst_amount - 1) * burst_delay)/max(burst_amount, 1), 0.0001)

// weapon info

data["icon"] = SSassets.transport.get_asset_url("no_name.png")

if(SSassets.cache["[base_gun_icon].png"])
data["icon"] = SSassets.transport.get_asset_url("[base_gun_icon].png")

data["icon"] = base_gun_icon
data["name"] = name
data["desc"] = desc
data["two_handed_only"] = (flags_gun_features & GUN_WIELDED_FIRING_ONLY)
Expand All @@ -688,19 +678,18 @@ As sniper rifles have both and weapon mods can change them as well. ..() deals w
data["damage"] = damage
data["falloff"] = falloff
data["total_projectile_amount"] = bonus_projectile_amount+1
data["armor_punch"] = armor_punch
data["penetration"] = penetration
data["accuracy"] = accuracy * accuracy_mult
data["unwielded_accuracy"] = accuracy * accuracy_mult_unwielded
data["min_accuracy"] = min_accuracy
data["max_range"] = max_range
data["effective_range"] = effective_range

// damage table data

data["damage_armor_profile_headers"] = damage_armor_profile_headers
data["damage_armor_profile_marine"] = damage_armor_profile_marine
data["damage_armor_profile_xeno"] = damage_armor_profile_xeno
data["damage_armor_profile_armorbreak"] = damage_armor_profile_armorbreak

return data

Expand All @@ -715,19 +704,19 @@ As sniper rifles have both and weapon mods can change them as well. ..() deals w
data["damage_max"] = 100
data["accuracy_max"] = 32
data["range_max"] = 32
data["effective_range_max"] = EFFECTIVE_RANGE_MAX_TIER_4
data["falloff_max"] = DAMAGE_FALLOFF_TIER_1
data["penetration_max"] = ARMOR_PENETRATION_TIER_10
data["punch_max"] = 5
data["glob_armourbreak"] = GLOB.xeno_general.armor_ignore_integrity
data["automatic"] = (GUN_FIREMODE_AUTOMATIC in gun_firemode_list)
data["auto_only"] = ((length(gun_firemode_list) == 1) && (GUN_FIREMODE_AUTOMATIC in gun_firemode_list))

return data

/obj/item/weapon/gun/ui_assets(mob/user)
. = ..() || list()
. += get_asset_datum(/datum/asset/simple/firemodes)
//. += get_asset_datum(/datum/asset/spritesheet/gun_lineart)
. += get_asset_datum(/datum/asset/spritesheet/gun_lineart_modes)
. += get_asset_datum(/datum/asset/spritesheet/gun_lineart)

// END TGUI \\
Expand Down
4 changes: 1 addition & 3 deletions code/modules/projectiles/guns/pistols.dm
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
icon = 'icons/obj/items/weapons/guns/guns_by_faction/colony.dmi'
icon_state = "c_deagle"
item_state = "c_deagle"
base_gun_icon = "c_deagle"
current_mag = /obj/item/ammo_magazine/pistol/heavy/super/highimpact
black_market_value = 100

Expand All @@ -257,7 +256,6 @@
desc = "A Desert Eagle anodized in gold and adorned with rosewood grips. The living definition of ostentatious, it's flashy, unwieldy, tremendously heavy, and kicks like a mule. But as a symbol of power, there's nothing like it."
icon_state = "g_deagle"
item_state = "g_deagle"
base_gun_icon = "g_deagle"

//-------------------------------------------------------
//NP92 pistol
Expand Down Expand Up @@ -588,7 +586,7 @@
name = "\improper 88 Mod 4 combat pistol"
desc = "Standard issue USCM firearm. Also found in the hands of Weyland-Yutani PMC teams. Fires 9mm armor shredding rounds and is capable of 3-round burst."
icon = 'icons/obj/items/weapons/guns/guns_by_faction/uscm.dmi'
icon_state = "88m4"
icon_state = "_88m4" // to comply with css standards
item_state = "88m4"
fire_sound = "88m4"
firesound_volume = 20
Expand Down
4 changes: 4 additions & 0 deletions code/modules/unit_tests/spritesheets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
/datum/unit_test/spritesheets

/datum/unit_test/spritesheets/Run()
var/regex/valid_css_class = new(@"^([\l_][\w\-]|[\l_\-][\l_])")
for(var/datum/asset/spritesheet/sheet as anything in subtypesof(/datum/asset/spritesheet))
if(!initial(sheet.name)) //Ignore abstract types
continue
sheet = get_asset_datum(sheet)
for(var/sprite_name in sheet.sprites)
if(!sprite_name)
TEST_FAIL("Spritesheet [sheet.type] has a nameless icon state.")
if(!valid_css_class.Find(sprite_name))
// https://www.w3.org/TR/CSS2/syndata.html#value-def-identifier
TEST_FAIL("Spritesheet [sheet.type] has a icon state that doesn't comply with css standards: '[sprite_name]'.")
Binary file modified icons/obj/items/weapons/guns/guns_by_faction/uscm.dmi
Binary file not shown.
Binary file modified icons/obj/items/weapons/guns/lineart.dmi
Binary file not shown.
Binary file added icons/obj/items/weapons/guns/lineart_modes.dmi
Binary file not shown.
Binary file removed nano/images/weapons/88m4.png
Binary file not shown.
Binary file removed nano/images/weapons/aamateba.png
Binary file not shown.
Binary file removed nano/images/weapons/amateba.png
Binary file not shown.
Binary file removed nano/images/weapons/auto.png
Binary file not shown.
Binary file removed nano/images/weapons/auto9.png
Binary file not shown.
Binary file removed nano/images/weapons/b92fs.png
Binary file not shown.
Binary file removed nano/images/weapons/burst.png
Binary file not shown.
Binary file removed nano/images/weapons/c70.png
Binary file not shown.
Binary file removed nano/images/weapons/c_deagle.png
Binary file not shown.
Binary file removed nano/images/weapons/cmateba.png
Binary file not shown.
Binary file removed nano/images/weapons/cshotgun.png
Binary file not shown.
Binary file removed nano/images/weapons/dartgun.png
Binary file not shown.
Binary file removed nano/images/weapons/deagle.png
Binary file not shown.
Binary file removed nano/images/weapons/disabled_automatic.png
Binary file not shown.
Binary file removed nano/images/weapons/disabled_burst.png
Binary file not shown.
Binary file removed nano/images/weapons/disabled_single.png
Binary file not shown.
Binary file removed nano/images/weapons/dshotgun.png
Binary file not shown.
Binary file removed nano/images/weapons/fp9000.png
Binary file not shown.
Binary file removed nano/images/weapons/fp9000_pmc.png
Binary file not shown.
Binary file removed nano/images/weapons/g_deagle.png
Binary file not shown.
Binary file removed nano/images/weapons/hg3712.png
Binary file not shown.
Binary file removed nano/images/weapons/highpower.png
Binary file not shown.
Binary file removed nano/images/weapons/holdout.png
Binary file not shown.
Binary file removed nano/images/weapons/hunting.png
Binary file not shown.
Binary file removed nano/images/weapons/kt42.png
Binary file not shown.
Binary file removed nano/images/weapons/l42mk1.png
Diff not rendered.
Binary file removed nano/images/weapons/m16.png
Diff not rendered.
Binary file removed nano/images/weapons/m240.png
Diff not rendered.
Binary file removed nano/images/weapons/m240t.png
Diff not rendered.
Binary file removed nano/images/weapons/m37-17.png
Diff not rendered.
Binary file removed nano/images/weapons/m37.png
Diff not rendered.
Binary file removed nano/images/weapons/m39.png
Diff not rendered.
Binary file removed nano/images/weapons/m41a.png
Diff not rendered.
Binary file removed nano/images/weapons/m41a2.png
Diff not rendered.
Binary file removed nano/images/weapons/m41ae2.png
Diff not rendered.
Binary file removed nano/images/weapons/m41amk1.png
Diff not rendered.
Binary file removed nano/images/weapons/m41b.png
Diff not rendered.
Binary file removed nano/images/weapons/m42a.png
Diff not rendered.
Binary file removed nano/images/weapons/m42c.png
Diff not rendered.
Binary file removed nano/images/weapons/m44r.png
Diff not rendered.
Binary file removed nano/images/weapons/m44rc.png
Diff not rendered.
Binary file removed nano/images/weapons/m46c.png
Diff not rendered.
Binary file removed nano/images/weapons/m4a3.png
Diff not rendered.
Binary file removed nano/images/weapons/m4a345.png
Diff not rendered.
Binary file removed nano/images/weapons/m4a3c.png
Diff not rendered.
Binary file removed nano/images/weapons/m5.png
Diff not rendered.
Binary file removed nano/images/weapons/m56.png
Diff not rendered.
Binary file removed nano/images/weapons/m57a4.png
Diff not rendered.
Binary file removed nano/images/weapons/m60.png
Diff not rendered.
Binary file removed nano/images/weapons/m79.png
Diff not rendered.
Binary file removed nano/images/weapons/m81.png
Diff not rendered.
Binary file removed nano/images/weapons/m82f.png
Diff not rendered.
Binary file removed nano/images/weapons/m92.png
Diff not rendered.
Binary file removed nano/images/weapons/m93b2.png
Diff not rendered.
Binary file removed nano/images/weapons/mac15.png
Diff not rendered.
Binary file removed nano/images/weapons/mar30.png
Diff not rendered.
Binary file removed nano/images/weapons/mar40.png
Diff not rendered.
Binary file removed nano/images/weapons/mateba.png
Diff not rendered.
Binary file removed nano/images/weapons/mk221.png
Diff not rendered.
Binary file removed nano/images/weapons/mou.png
Diff not rendered.
Binary file removed nano/images/weapons/mp5.png
Diff not rendered.
Binary file removed nano/images/weapons/mp7.png
Diff not rendered.
Binary file removed nano/images/weapons/no_name.png
Diff not rendered.
Binary file removed nano/images/weapons/ny762.png
Diff not rendered.
Binary file removed nano/images/weapons/painless.png
Diff not rendered.
Binary file removed nano/images/weapons/pk9.png
Diff not rendered.
Binary file removed nano/images/weapons/pk9r.png
Diff not rendered.
Binary file removed nano/images/weapons/pk9u.png
Diff not rendered.
Binary file removed nano/images/weapons/ppsh17b.png
Diff not rendered.
Binary file removed nano/images/weapons/single.png
Diff not rendered.
Binary file removed nano/images/weapons/skorpion.png
Diff not rendered.
Binary file removed nano/images/weapons/skorpion_u.png
Diff not rendered.
Binary file removed nano/images/weapons/smartpistol.png
Diff not rendered.
Binary file removed nano/images/weapons/spearhead.png
Diff not rendered.
Binary file removed nano/images/weapons/sshotgun.png
Diff not rendered.
Binary file removed nano/images/weapons/supremo.png
Diff not rendered.
Binary file removed nano/images/weapons/svd003.png
Diff not rendered.
Binary file removed nano/images/weapons/sw357.png
Diff not rendered.
Binary file removed nano/images/weapons/sw358.png
Diff not rendered.
Binary file removed nano/images/weapons/syringegun.png
Diff not rendered.
Binary file removed nano/images/weapons/taser.png
Diff not rendered.
Binary file removed nano/images/weapons/type71.png
Diff not rendered.
Binary file removed nano/images/weapons/type71c.png
Diff not rendered.
Binary file removed nano/images/weapons/type73.png
Diff not rendered.
Binary file removed nano/images/weapons/vp78.png
Diff not rendered.
Binary file removed nano/images/weapons/xm42b.png
Diff not rendered.
72 changes: 41 additions & 31 deletions tgui/packages/tgui/interfaces/WeaponStats.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { map } from 'common/collections';
import { classes } from 'common/react';

import { useBackend } from '../backend';
import { Box, Divider, Flex, ProgressBar, Section, Table } from '../components';
Expand Down Expand Up @@ -68,7 +69,7 @@ const GeneralInfo = (props) => {
<Flex.Item align="center">
<Box height="5px" />
<Box align="center">
<img src={resolveAsset(icon)} />
<span className={classes(['Icon', 'gunlineart96x96', `${icon}`])} />
</Box>
<Box height="5px" />
</Flex.Item>
Expand All @@ -78,25 +79,33 @@ const GeneralInfo = (props) => {
<Flex.Item align="center">
<Flex direction="row">
<Flex.Item>
{!auto_only ? (
<img src={resolveAsset('single.png')} />
) : (
<img src={resolveAsset('disabled_single.png')} />
)}
<span
className={classes([
'Icon',
'gunlineartmodes96x32',
`${!auto_only ? 'single' : 'disabled_single'}`,
])}
/>
</Flex.Item>
<Flex.Item>
{!auto_only && burst_amount > 1 ? (
<img src={resolveAsset('burst.png')} />
) : (
<img src={resolveAsset('disabled_burst.png')} />
)}
<span
className={classes([
'Icon',
'gunlineartmodes96x32',
`${
!auto_only && burst_amount > 1 ? 'burst' : 'disabled_burst'
}`,
])}
/>
</Flex.Item>
<Flex.Item>
{automatic ? (
<img src={resolveAsset('auto.png')} />
) : (
<img src={resolveAsset('disabled_automatic.png')} />
)}
<span
className={classes([
'Icon',
'gunlineartmodes96x32',
`${automatic ? 'auto' : 'disabled_automatic'}`,
])}
/>
</Flex.Item>
</Flex>
</Flex.Item>
Expand Down Expand Up @@ -272,13 +281,27 @@ const Accuracy = (props) => {

const Range = (props) => {
const { data } = useBackend();
const { max_range, range_max, falloff, falloff_max } = data;
const {
max_range,
range_max,
falloff,
falloff_max,
effective_range,
effective_range_max,
} = data;
return (
<>
<ProgressBar value={max_range / range_max} ranges={RedGreenRange}>
Max range: {max_range} / {range_max}
</ProgressBar>
<Box height="5px" />
<ProgressBar
value={effective_range / effective_range_max}
ranges={RedGreenRange}
>
Effective range: {effective_range}
</ProgressBar>
<Box height="5px" />
<ProgressBar value={falloff / falloff_max} ranges={GreedRedRange}>
Falloff: {falloff} / {falloff_max}
</ProgressBar>
Expand All @@ -289,16 +312,13 @@ const Range = (props) => {

const ArmourPen = (props) => {
const { data } = useBackend();
const { penetration, penetration_max, armor_punch, punch_max } = data;
const { penetration, penetration_max } = data;
return (
<>
<ProgressBar value={penetration / penetration_max} ranges={RedGreenRange}>
Armour penetration: {penetration} / {penetration_max}
</ProgressBar>
<Box height="5px" />
<ProgressBar value={armor_punch / punch_max} ranges={RedGreenRange}>
Armour punch: {armor_punch} / {punch_max}
</ProgressBar>
</>
);
};
Expand All @@ -308,9 +328,7 @@ const DamageTable = (props) => {
const {
damage_armor_profile_marine,
damage_armor_profile_xeno,
damage_armor_profile_armorbreak,
damage_armor_profile_headers,
glob_armourbreak,
} = data;
return (
<Section title="Damage table">
Expand All @@ -337,14 +355,6 @@ const DamageTable = (props) => {
<Table.Cell key={i}>{entry}</Table.Cell>
))}
</Table.Row>
{!glob_armourbreak ? (
<Table.Row>
<Table.Cell textAlign="left">Armor break</Table.Cell>
{map(damage_armor_profile_armorbreak, (entry, i) => (
<Table.Cell key={i}>{entry}</Table.Cell>
))}
</Table.Row>
) : null}
</Table>
</Section>
);
Expand Down

0 comments on commit 36ffd34

Please sign in to comment.