Skip to content

Commit

Permalink
Additional dmi testing for duplicates and quantity (#3867)
Browse files Browse the repository at this point in the history
# About the pull request

This PR adds additional lints for dmi files: duplicate state names and a
check if the count of states exceeds 512. (My first attempt at this was
to modify the missing_icons unit test, but the icon_states proc ignores
duplicate states.)

Let me know if you would like the items_left/righthand files balanced
more or if theres anything I may have missed. We don't currently have
unit testing for on_mob icons due to how many just simply don't have
icons.

# Explain why it's good for the game

Helps prevent accidental errors in DMI files that might otherwise get
overlooked, and finishes the work that was started in #3895 .

# Testing Photographs and Procedure
<details>
<summary>Screenshots & Videos</summary>


![image](https://github.com/cmss13-devs/cmss13/assets/76988376/f8623d3e-37b4-4a10-84e5-1b58eb492823)

![image](https://github.com/cmss13-devs/cmss13/assets/76988376/c95ea11f-e188-424b-b330-b27bec294cc9)

</details>

# Changelog
:cl: Drathek
code: Added additional lints to dmi/test.py to test for duplicate state
names and excessive quantity and added another type path to the
missing_icons unit_test.
imageadd: Renamed and moved some icons around to comply with new
testing.
/:cl:
  • Loading branch information
Drulikar authored Jul 24, 2023
1 parent d736dba commit 7b8ccd4
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions code/game/objects/items/reagent_containers/food.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
/// Food.
////////////////////////////////////////////////////////////////////////////////
/obj/item/reagent_container/food
item_icons = list(
WEAR_L_HAND = 'icons/mob/humans/onmob/items_lefthand_1.dmi',
WEAR_R_HAND = 'icons/mob/humans/onmob/items_righthand_1.dmi'
)
possible_transfer_amounts = null
volume = 50 //Sets the default container amount for all food items.
flags_atom = CAN_BE_SYRINGED
Expand Down
4 changes: 4 additions & 0 deletions code/game/objects/items/storage/belt.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
desc = "Can hold various things."
icon = 'icons/obj/items/clothing/belts.dmi'
icon_state = "utilitybelt"
item_icons = list(
WEAR_L_HAND = 'icons/mob/humans/onmob/items_lefthand_1.dmi',
WEAR_R_HAND = 'icons/mob/humans/onmob/items_righthand_1.dmi'
)
item_state = "utility"
flags_equip_slot = SLOT_WAIST
attack_verb = list("whipped", "lashed", "disciplined")
Expand Down
1 change: 1 addition & 0 deletions code/modules/unit_tests/missing_icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/datum/unit_test/missing_icons/Run()
generate_possible_icon_states_list()
generate_possible_icon_states_list("icons/effects/")
generate_possible_icon_states_list("icons/mobs/")
if(additional_icon_location)
generate_possible_icon_states_list(additional_icon_location)

Expand Down
Binary file modified icons/mob/hud/human_old.dmi
Binary file not shown.
Binary file modified icons/mob/humans/onmob/items_lefthand_0.dmi
Binary file not shown.
Binary file modified icons/mob/humans/onmob/items_lefthand_1.dmi
Binary file not shown.
Binary file modified icons/mob/humans/onmob/items_righthand_0.dmi
Binary file not shown.
Binary file modified icons/mob/humans/onmob/items_righthand_1.dmi
Binary file not shown.
Binary file modified icons/obj/structures/props/rocks.dmi
Binary file not shown.
Binary file modified icons/rebase_icons.dmi
Binary file not shown.
Binary file modified icons/turf/floors/desert_dirt.dmi
Binary file not shown.
Binary file modified icons/turf/floors/desert_rock.dmi
Binary file not shown.
37 changes: 34 additions & 3 deletions tools/dmi/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,54 @@
from dmi import *


def green(text):
return "\033[32m" + str(text) + "\033[0m"


def red(text):
return "\033[31m" + str(text) + "\033[0m"


def _self_test():
# test: can we load every DMI in the tree
count = 0
failed = 0
for dirpath, dirnames, filenames in os.walk('.'):
if '.git' in dirnames:
dirnames.remove('.git')
for filename in filenames:
if filename.endswith('.dmi'):
fullpath = os.path.join(dirpath, filename)
failures_this_file = 0
try:
Dmi.from_file(fullpath)
dmi = Dmi.from_file(fullpath)
dmi_states = dmi.states
number_of_icon_states = len(dmi.states)
if number_of_icon_states > 512:
print("{0} {1} has too many icon states: {2}/512.".format(red("FAIL"), fullpath, number_of_icon_states))
failures_this_file += 1
existing_states = []
for state in dmi_states:
state_name = state.name
if state.movement:
state_name += "_MOVEMENT_STATE_TRUE"
if state_name in existing_states:
print("{0} {1} has a duplicate state '{2}'.".format(red("FAIL"), fullpath, state.name))
failures_this_file += 1
continue
existing_states.append(state_name)
except Exception:
print('Failed on:', fullpath)
print("{0} {1} threw an exception.".format(red("FAIL"), fullpath))
failures_this_file += 1
raise
count += 1
if failures_this_file > 0:
failed += 1

print(f"{os.path.relpath(__file__)}: successfully parsed {count} .dmi files")
print(f"{os.path.relpath(__file__)}: {green(f'successfully parsed {count-failed} .dmi files')}")
if failed > 0:
print(f"{os.path.relpath(__file__)}: {red(f'failed to parse {failed} .dmi files')}")
exit(1)


def _usage():
Expand Down

0 comments on commit 7b8ccd4

Please sign in to comment.