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

turn bare materials into objects #47015

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions data/json/items/comestibles/carnivore.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"description": "Fresh blood extracted from a living creature.",
"healthy": 0,
"parasites": 0,
"material": "blood",
"material": [ "blood" ],
"quench": 5,
"comestible_type": "DRINK",
"looks_like": "blood",
Expand Down Expand Up @@ -253,7 +253,7 @@
"quench": 5,
"looks_like": "blood",
"symbol": "~",
"material": "blood",
"material": [ "blood" ],
"phase": "liquid",
"delete": { "flags": [ "SMOKABLE" ] }
},
Expand Down Expand Up @@ -290,7 +290,7 @@
"quench": 5,
"looks_like": "blood",
"symbol": "~",
"material": "hblood",
"material": [ "hblood" ],
"phase": "liquid",
"delete": { "flags": [ "SMOKABLE" ] }
},
Expand Down Expand Up @@ -884,7 +884,7 @@
"quench": 5,
"looks_like": "blood",
"symbol": "~",
"material": "blood",
"material": [ "blood" ],
"phase": "liquid",
"delete": { "flags": [ "SMOKABLE" ] }
},
Expand Down Expand Up @@ -1277,7 +1277,7 @@
"quench": 5,
"looks_like": "blood",
"symbol": "~",
"material": "blood",
"material": [ "blood" ],
"phase": "liquid",
"delete": { "flags": [ "SMOKABLE" ] }
},
Expand Down
2 changes: 1 addition & 1 deletion data/json/items/comestibles/med.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"volume": "150 ml",
"price": 600,
"price_postapoc": 200,
"material": "cotton",
"material": [ "cotton" ],
"symbol": "!",
"color": "white",
"charges": 10,
Expand Down
4 changes: 2 additions & 2 deletions data/json/items/gun/9mm.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
"price_postapoc": 2500,
"to_hit": -2,
"bashing": 8,
"material": "steel",
"material": [ "steel" ],
"symbol": "(",
"color": "dark_gray",
"ammo": [ "9mm" ],
Expand Down Expand Up @@ -437,7 +437,7 @@
"price_postapoc": 2500,
"to_hit": -2,
"bashing": 8,
"material": "steel",
"material": [ "steel" ],
"symbol": "(",
"color": "dark_gray",
"ammo": [ "9mm" ],
Expand Down
10 changes: 5 additions & 5 deletions data/json/items/magazine/10mm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"volume": "250 ml",
"price": 1500,
"price_postapoc": 100,
"material": "steel",
"material": [ "steel" ],
"symbol": "#",
"color": "light_gray",
"ammo_type": [ "40", "10mm" ],
Expand Down Expand Up @@ -61,7 +61,7 @@
"description": "An 8-round single stack steel box magazine for use with 1911 pattern guns chambered in 10mm Auto.",
"price": 3500,
"price_postapoc": 100,
"material": "steel",
"material": [ "steel" ],
"ammo_type": [ "10mm" ],
"pocket_data": [ { "pocket_type": "MAGAZINE", "rigid": true, "ammo_restriction": { "10mm": 8 } } ]
},
Expand Down Expand Up @@ -94,7 +94,7 @@
"longest_side": "141 mm",
"price": 4000,
"price_postapoc": 100,
"material": "steel",
"material": [ "steel" ],
"symbol": "#",
"color": "light_gray",
"ammo_type": [ "10mm" ],
Expand Down Expand Up @@ -130,7 +130,7 @@
"longest_side": "134 mm",
"price": 2600,
"price_postapoc": 100,
"material": "steel",
"material": [ "steel" ],
"symbol": "#",
"color": "light_gray",
"ammo_type": [ "10mm" ],
Expand All @@ -148,7 +148,7 @@
"longest_side": "124 mm",
"price": 2800,
"price_postapoc": 100,
"material": "steel",
"material": [ "steel" ],
"symbol": "#",
"color": "light_gray",
"ammo_type": [ "10mm" ],
Expand Down
4 changes: 2 additions & 2 deletions data/json/items/magazine/9mm.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@
"longest_side": "14 cm",
"price": 4000,
"price_postapoc": 100,
"material": "steel",
"material": [ "steel" ],
"symbol": "#",
"color": "light_gray",
"ammo_type": "9mm",
Expand All @@ -445,7 +445,7 @@
"longest_side": "22 cm",
"price": 9000,
"price_postapoc": 200,
"material": "steel",
"material": [ "steel" ],
"symbol": "#",
"color": "light_gray",
"ammo_type": "9mm",
Expand Down
2 changes: 1 addition & 1 deletion data/json/items/magazine/nail.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"weight": "60 g",
"volume": "250 ml",
"price": 1920,
"material": "steel",
"material": [ "steel" ],
"symbol": "#",
"color": "light_gray",
"ammo_type": "nail",
Expand Down
2 changes: 1 addition & 1 deletion data/json/items/resources/stone.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"name": { "str": "large rock" },
"description": "A heavy and large rock, big enough to be used as a primitive anvil, or shaped into larger stone items.",
"category": "spare_parts",
"material": "stone",
"material": [ "stone" ],
"weight": "15768 g",
"volume": "6 L",
"longest_side": "30 cm",
Expand Down
2 changes: 1 addition & 1 deletion data/json/items/tool/metalworking.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
"volume": "500 ml",
"price": 1600,
"price_postapoc": 10,
"material": "paper",
"material": [ "paper" ],
"symbol": "`",
"color": "brown",
"qualities": [ [ "FILE", 1 ] ]
Expand Down
8 changes: 4 additions & 4 deletions data/json/items/tool/stoneworking.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "A thick short bone, usually used in flintknapping for soft-hammer percussion.",
"category": "tools",
"price": 10,
"material": "bone",
"material": [ "bone" ],
"weight": "150 g",
"volume": "250 ml",
"longest_side": "20 cm",
Expand All @@ -25,7 +25,7 @@
"description": "A thick short wooden stick, usually used in flintknapping for soft-hammer percussion.",
"category": "tools",
"price": 10,
"material": "wood",
"material": [ "wood" ],
"weight": "150 g",
"volume": "250 ml",
"longest_side": "20 cm",
Expand All @@ -42,7 +42,7 @@
"description": "A thick blunted wooden stick. Can be used to drill rough holes in rock, if water and sand are available, but the process is lengthy.",
"category": "tools",
"price": 10,
"material": "wood",
"material": [ "wood" ],
"weight": "150 g",
"volume": "250 ml",
"longest_side": "20 cm",
Expand All @@ -59,7 +59,7 @@
"description": "A thick short bone with a small pointy tip, usually used in flintknapping for indirect percussion and pressure flaking.",
"category": "tools",
"price": 10,
"material": "bone",
"material": [ "bone" ],
"weight": "150 g",
"volume": "250 ml",
"longest_side": "15 cm",
Expand Down
2 changes: 1 addition & 1 deletion data/json/obsolete.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
"volume": "1250 ml",
"price": 3000,
"price_postapoc": 3000,
"material": "plastic",
"material": [ "plastic" ],
"symbol": "!",
"color": "red",
"use_action": "DISASSEMBLE",
Expand Down
55 changes: 55 additions & 0 deletions tools/json_tools/material_ammo_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python3

# Make sure you have python3 installed.
# Ensure that the json_formatter is kept in Tools with this script.
# For Windows:
# Using command prompt type "python material_ammo_update.py"
# For Max OS X or Linux:
# Swap any "\\" with "/", then run the script as in windows.

import json
import os


def gen_new(path):
change = False
with open(path, "r") as json_file:
try:
json_data = json.load(json_file)
except UnicodeDecodeError:
print(f"UnicodeDecodeError in {path}")
return None
except json.decoder.JSONDecodeError:
print(f"UnicodeDecodeError in {path}")
return None
for jo in json_data:
# We only want JsonObjects
if type(jo) is str:
continue
if type(jo.get('material')) == str:
material = jo['material']
jo['material'] = [material]
change = True
if type(jo.get('ammo')) == str and jo.get('type') == 'ammo':
ammo = jo['ammo']
jo['ammo'] = [ammo]
change = True

return json_data if change else None


def change_file(json_dir):
for root, directories, filenames in os.walk(f"..\\{json_dir}"):
for filename in filenames:
path = os.path.join(root, filename)
if path.endswith(".json"):
new = gen_new(path)
if new is not None:
with open(path, "w") as jf:
json.dump(new, jf, ensure_ascii=False)
os.system(f".\\json_formatter.exe {path}")


if __name__ == "__main__":
json_dir = input("What directory are the json files in? ")
change_file(json_dir)