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

Modernize more volume and weight #41704

Merged

Conversation

hexagonrecursion
Copy link
Contributor

@hexagonrecursion hexagonrecursion commented Jun 30, 2020

Summary

SUMMARY: none

Purpose of change

Contributes to #36110

Describe the solution

Convert weights and volumes to strings.

Describe alternatives you've considered

none

Testing

  1. Create a world with the following mods
  • Disable NPC Needs
  • Aftershock
  • CRIT Expansion
  • DinoMod
  • Generic Guns
  • Magiclysm
  1. Test that a new game can be started in it
  2. Test the amount of water that fits into a steel jerrycan stayed the same (80 units)
  3. Test that 80 units of water (20L; 1 full steel jerrycan) weigh 20kg
  4. Note: I did not do any testing for changes to data/legacy//.json because I don't know how to wish for legacy items
  5. Test that the volume of 1000 nutriments (id: afs_calorie_pill) stayed the same (0.2L)
  6. Test that the volume of 1000 CQB SI shotguns stayed the same (1 L)
  7. Test that the weight and volume of Dilophosaurus stayed the same (400 L; 400 kg)
  8. Test that the weight and volume of 1000 grenade belts (id: belt40mm) stayed the same (1L; 0 kg)
  9. Note: I did not test some of the affected items

Additional context

This patch was brought to you by the following script:

#!/usr/bin/env bash
set -eux

echo "Using JSON formatter: ${JSON_FORMATTER:=tools/format/json_formatter.cgi}"
echo

# The data/ directory is a mess:
# 1. It has a json/ subdirectory even though there is plenty of JSON
#    outside that subdirectory.
# 2. Most JSON files in data/ have a uniform structure (see example 1 below),
#    but there are exceptions - files that have a completely different structure.
# The following command collects the names of all the files that use the uniform
# structure ignoring all files that don't. It also looks in utilities/.
# Even though utilities/ does not contain any loadable data, it contains
# examples. I want to modernize the documentation too.
#
# example 1
# [
#   {"type": "foo", ...},
#   {"type": "bar", ...}
# ]
#
mapfile -t FILES < <(
	find utilities data \
		-name '*.json' \
		-not -path 'data/raw/color_templates/no_bright_background.json' \
		-not -path 'data/names/*' \
		-not -path 'data/mods/replacements.json' \
		-not -path 'data/fontdata.json' \
)

# Piping game data through jq introduces some noise because jq does not
# distinguish between 123.0 and 123. I use some git rebase magic
# to work around this issue. After running this script run:
# git rebase --onto=master modernize-volume-weight-noise modernize-volume-weight-2
git checkout -b modernize-volume-weight-noise master
for F in "${FILES[@]}"; do
	echo "noise: $F"
	jq '.' "$F" | $JSON_FORMATTER | sponge "$F"
done
git add .
git commit -m 'DO NOT MERGE'

JQ='
(
  .[] 
  | select(.type!="mapgen")
  | .weight
  | numbers
) |= if .%1000 == 0 then "\(./1000) kg" else "\(.) g" end
| (
  .[]
  | select(.type!="speech" and .type!="sound_effect")
  | .volume
  | numbers
) |= (./4*1000 | if .%1000 == 0 then "\(./1000) L" else "\(.) ml" end)
'
git checkout -b modernize-volume-weight-2 modernize-volume-weight-noise
for F in "${FILES[@]}"; do
	echo "$F"
	jq "$JQ" "$F" | $JSON_FORMATTER | sponge "$F"
done
git add .
git commit -m 'Modernize more volume and weight'

@@ -868,7 +868,7 @@
"symbol": "D",
"color": "magenta_green",
"volume": "400000 ml",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this is merged I'll create a separate PR to replace "400000 ml" with "volume": "400 L"

@hexagonrecursion hexagonrecursion marked this pull request as ready for review June 30, 2020 19:18
@anothersimulacrum anothersimulacrum added [JSON] Changes (can be) made in JSON Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Jun 30, 2020
@kevingranade kevingranade merged commit 80bf30d into CleverRaven:master Jul 1, 2020
@hexagonrecursion hexagonrecursion deleted the modernize-volume-weight-2 branch July 1, 2020 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style [JSON] Changes (can be) made in JSON
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants