Skip to content

Commit

Permalink
Create dme for ease of use in icons
Browse files Browse the repository at this point in the history
Other groundwork
  • Loading branch information
babydoll committed Sep 2, 2019
1 parent 963bd5d commit 7ca45ce
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python
sudo: false
script:
- python tools/CustomConfigVerifier/verify-custom-items.py config/custom_items.txt
- python tools/CustomConfigVerifier/verify-custom-items.py config/custom_items/
- python tools/CustomConfigVerifier/verify-custom-sprites.py config/custom_sprites.txt
38 changes: 17 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

3. Fill out the provided template in the directory of your choice. See chart below for an explanation of the values.

| Key | Expected Value | Function |
|-----------------|------------------|------------------------------------------------------------------------------------------------------------------|
| ckey | string | Your ckey. This is not quite the same as your BYOND key, ask an admin or check the BYOND docs if you are unsure. |
| character_name | string | The name of the character the item should spawn with. |
| item_name | string | The name of your custom item ingame. For kits, the name of the kit product. |
| item_desc | string | The description of your custom item ingame. For kits, the descriptor for the kit product. |
| item_icon_state | string | The icon state for your custom item. For kits, the icon state of the kit product. |
| item_path | string | A fully specified BYOND object path (ie. /obj/item/foo/bar). |
| inherit_inhands | true/false | Whether or not it should override the inhands of the base item. |
| req_access | array of strings | Access strings required for the character to have this item on spawn. |
| req_titles | array of strings | Titles and alt titles that are allowed to spawn with this item. |
| additional_data | array of values | An associative list of other values. Currently used fields: "light_overlay". |
| Key | Expected Value | Function |
|------------------------|------------------|-------------------------------------------------------------------------------------------------------------------|
| ckey | string | Your ckey. This is not quite the same as your BYOND key, ask an admin or check the BYOND docs if you are unsure. |
| character_name | string | The name of the character the item should spawn with. |
| item_name | string | The name of your custom item ingame. For kits, the name of the kit product. |
| item_desc | string | The description of your custom item ingame. For kits, the descriptor for the kit product. |
| item_icon_state | string | The icon state for your custom item. For kits, the icon state of the kit product. |
| item_path | string | A fully specified BYOND object path (ie. /obj/item/foo/bar). |
| apply_to_target_type | string | A fully specified BYOND object path (ie. /obj/item/foo/bar) Only set this if you are reskinning an existing item. |
| req_access | array of strings | Access strings required for the character to have this item on spawn. |
| req_titles | array of strings | Titles and alt titles that are allowed to spawn with this item. |
| additional_data | array of values | An associative list of other values. Currently used fields: "light_overlay". |

**Note** - All icons should be added to the **END** of the relevant file. This helps organisation.

Expand All @@ -26,15 +26,11 @@

6. If the item is wearable, add an icon to icons/mob/custom_items.dmi for the on-mob icon.

7. For mechs, add three icons to icons/obj/custom_items.dmi - kit_icon, kit_icon-open and kit_icon-broken. These are the mech icon, the icon when stationary and without a pilot, and the wreckage icon respectively. You're done now, good work.
8. For voidsuit kits:
- Add two icons to icons/obj/custom_items.dmi - the icon for the suit, and the helmet, both assigned as `item_icon_state` in your .json file. These icons represent the suit parts when in your inventory.
- Add four icons to icons/mob/custom_items.dmi. These are the two in-hand icons (see step 5), the helmet, and the suit. These icons represent the suit parts when held in your hands or equipped. If you already added your in-hand icons in step 5, just add the helmet and suit on-mob icons.

8. For suits, add two icons to icons/obj/custom_items.dmi - kit_icon_suit and kit_icon_helmet. These icons represent the suit parts when in inventory.

9. Add four icons to icons/mob/custom_items.dmi. You need to add in-hand icons (see 3) for both kit_icon_suit and kit_icon_helmet.

10. Add a final two icons to icons/mob/custom_items.dmi under kit_icon_suit and kit_icon_helmet for the on-mob icons.

11. You're done. Compile, test, and discover you misspelled a state, etc.
11. You're done. Compile, test (see final section below), and discover you misspelled a state, etc.

## How to add a custom robot icon sheet
1. Add a config entry to custom_sprites.txt:
Expand Down Expand Up @@ -84,5 +80,5 @@ ckey-robotname
1. Create a .json file as directed above, and place it in the `config/custom_items` directory of your local copy of your main repository (eg. Baystation12)
3. Change ckey in the definition to YOUR CKEY. Change name to a character name you will be using for testing, or just use their name.
4. Add the relevant icons to the relevant files in your main repo folder.
5. Compile and run the game. Ready up, taking note of any job or access restrictions, and start the round. If you did it all correctly, you will have spawned the custom item. If not, it should hopefully give you an error message that can point you in the right direction.
5. Compile and run the game. Ready up, taking note of any job or access restrictions, and start the round. If you did it all correctly, you will have spawned the custom item. If not, it should hopefully print an error to world.log.
6. Once you're done testing, make sure you revert any changes made in your main repo folder. Do not push custom items related things to the main repo!
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"item_name" : "Joe's spear",
"item_desc" : "Joe's spear. It courses with basic energy.",
"item_icon_state" : "some_custom_spear_icon_state",
"item_path" : "/obj/item/real_path/to_an_item",
"inherit_inhands" : true,
"item_path" : "/obj/item/real_path/to_an_item"
"req_titles" : [ "Janitor" ],
"req_access" : [ "ACCESS_CAVEMAN" ]
}
18 changes: 18 additions & 0 deletions custom-items.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// DM Environment file for custom-items.dme.
// All manual changes should be made outside the BEGIN_ and END_ blocks.
// New source code should be placed in .dm files: choose File/New --> Code File.

// BEGIN_INTERNALS
// END_INTERNALS

// BEGIN_FILE_DIR
#define FILE_DIR .
// END_FILE_DIR

// BEGIN_PREFERENCES
#define DEBUG
// END_PREFERENCES

// BEGIN_INCLUDE
// END_INCLUDE

Binary file modified icons/custom_items_mob.dmi
Binary file not shown.
Binary file modified icons/custom_items_obj.dmi
Binary file not shown.
133 changes: 54 additions & 79 deletions tools/CustomConfigVerifier/verify-custom-items.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,100 +17,75 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
import argparse, re, sys

import json
import argparse
import re
import sys
import os
from collections import defaultdict
from os import path
from os import walk

opt = argparse.ArgumentParser()
opt.add_argument('path', help='The path to the custom item config to verify.')
opt.add_argument('path', help='The path to the root custom item directory to verify.')
args = opt.parse_args()

if(not path.isfile(args.path)):
print('Not a file: ' + args.path)
sys.exit(1)
if(not path.isdir(args.path)):
print('Not a directory: ' + args.path)
sys.exit(1)

errors = defaultdict(list)
mandatory_keys = ['ckey', 'character_name']

regex_lowercase_alphanumeric = re.compile('^[a-z0-9]*$')
regex_not_whitespace = re.compile('.*\S.*')
errors = defaultdict(list)
mandatory_keys = ['ckey', 'character_name']
key_value_alphanumeric = ['ckey']
key_value_no_whitespace = ['character_name', 'item_name', 'item_desc', 'item_path', 'item_icon_state']
key_value_array = ['req_access', 'req_titles']
key_value_dictionary = ['additional_data']

known_keys = {
'ckey': [regex_lowercase_alphanumeric],
'character_name': [regex_not_whitespace],
'item_path': [regex_not_whitespace],
'item_name': [regex_not_whitespace],
'item_icon': [regex_not_whitespace],
'inherit_inhands': [regex_not_whitespace],
'item_desc': [regex_not_whitespace],
'req_access': [regex_not_whitespace],
'req_titles': [regex_not_whitespace],
'kit_name': [regex_not_whitespace],
'kit_desc': [regex_not_whitespace],
'kit_icon': [regex_not_whitespace],
'additional_data': [regex_not_whitespace]
}

def verify_item_line(line, line_number, found_keys, errors):
if not ':' in line:
errors[line_number].append("No : found")
return

split = line.split(':', 1)
key = split[0].strip()
value = split[1].strip()

if not key in known_keys:
errors[line_number].append("Unknown key: %s" % key)
else:
found_keys[key] = found_keys[key] + 1
if found_keys[key] > 1:
errors[line_number].append("Duplicate key: %s" % key)
return
for regex in known_keys[key]:
if not regex.match(value):
errors[line_number].append("Invalid format: '%s'" % value)

def verify_block(line_number, found_keys, errors):
for mandatory_key in mandatory_keys:
if not mandatory_key in found_keys:
errors[line_number].append('Mandatory key missing: %s' % mandatory_key)

block_open = 0
line_number = 0
found_keys = defaultdict(int)

with open(args.path, 'r') as file:
for line in file:
line_number += 1
line = line.strip()
if (not line) or line.startswith('#'):
continue
if line == '{':
if block_open:
print('{ followed by {, expected }, at line %d' % line_number)
sys.exit(1)
block_open = 1
elif line == '}':
if not block_open:
print('} without preceding { at line %d' % line_number)
sys.exit(1)
block_open = 0
verify_block(line_number, found_keys, errors)
found_keys.clear()
else:
verify_item_line(line, line_number, found_keys, errors)
for root, dirs, files in os.walk(args.path):
for file in files:
if file.endswith('.json'):
inputPath = os.path.join(root, file)
try:
inputFile = open(inputPath, 'r')
inputJson = json.loads(inputFile.read())
inputFile.close()
for mandatory_key in mandatory_keys:
if not mandatory_key in inputJson:
errors[inputPath].append('Missing mandatory key: %s' % mandatory_key)
found_keys = defaultdict(int)
for key in inputJson:
found_keys[key] = found_keys[key] + 1
if found_keys[key] > 1:
print("1 %s" % key)
errors[inputPath].append('Duplicate key: %s' % key)
elif key in key_value_alphanumeric:
if not regex_lowercase_alphanumeric.match(inputJson[key]):
errors[inputPath].append("Invalid format - expected lowercase alphanumeric string: %s" % str(inputJson[key]))
elif key in key_value_no_whitespace:
if not regex_not_whitespace.match(inputJson[key]):
errors[inputPath].append("Invalid format - expected whitespace-free string: %s" % str(inputJson[key]))
elif key in key_value_array:
if not isinstance(inputJson[key], list):
errors[inputPath].append("Invalid format - expected list: %s" % str(inputJson[key]))
elif key in key_value_dictionary:
if not isinstance(inputJson[key], dict):
errors[inputPath].append("Invalid format - expected dictionary: %s" % str(inputJson[key]))
else:
errors[inputPath].append("Unknown key: %s" % key)
except Exception as ex:
template = "Exception of type {0}:\n{1!r}"
errors[inputPath].append(template.format(type(ex).__name__, ex.args))

for line_num, error_list in errors.items():
for file_path, error_list in errors.items():
if len(error_list) == 1:
print('%d: %s' % (line_num, error_list[0]))
print('%s: %s' % (file_path, error_list[0]))
else:
print(line_num)
print(file_path)
for error in error_list:
print("\t%s" % error)

if block_open:
print('Last block unclosed.')
sys.exit(1)
if len(errors) > 0:
sys.exit(1)

0 comments on commit 7ca45ce

Please sign in to comment.