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

Finish modernizing volume and weight #41627

Merged

Conversation

hexagonrecursion
Copy link
Contributor

@hexagonrecursion hexagonrecursion commented Jun 27, 2020

Summary

SUMMARY: none

Purpose of change

Contributes to #36110

Describe the solution

Convert the remaining weights and volumes to strings.

Describe alternatives you've considered

none

Testing

  1. The game loads
  2. The weight and volume of the .50 caliber rifle remain the same
  3. The weight and volume of the sawn-off .50 caliber rifle+1 remain the same

Additional context

This change was brought to you by the following script (mostly because I wanted to learn more about jq)

#!/usr/bin/env bash
# usage: ~/fix.sh ./tools/json/json_formatter.cgi
shopt -s globstar
JSON_FORMATTER=$1

# Create a rebase "upstream" to filter out the noise introduced by jq
git checkout -b modernize-volume-weight-noise master
for FILE in data/json/**/*.json; do
	echo "noise: $FILE"
	jq '.' "$FILE" | $JSON_FORMATTER | sponge "$FILE"
done
git add .
git commit -m 'DO NOT MERGE'

JQ='
(
  .[] 
  |
    (select(.type=="GENERIC" or .type=="GUN" or .type=="WHEEL") | .relative.weight),
    (select(.type=="trap") | .trigger_weight)
  | numbers
) |= if .%1000 == 0 then "\(./1000) kg" else "\(.) g" end
| (
  .[]
  |
    (select(.type=="GUN") | .relative.barrel_length, .relative.volume),
    (select(.type=="vehicle_part") | .folded_volume)
  | numbers
) |= (./4*1000 | if .%1000 == 0 then "\(./1000) L" else "\(.) ml" end)
'
git checkout -b modernize-volume-weight modernize-volume-weight-noise
for FILE in data/json/**/*.json; do
	echo "$FILE"
	jq "$JQ" "$FILE" | $JSON_FORMATTER | sponge "$FILE"
done
git add .
git commit -m 'Finish modernizing volume and weight'

After running the above script run:

git rebase --onto=master modernize-volume-weight-noise modernize-volume-weight

Notes: the script is more complicated than it could have been because of an inconsistency in the json formatting: json does not distinguish between 123.0 and 123 and the game data currently uses both. jq turns 123.0 into 123. Ideally in the future json_formatter.cgi would normalize the representation of numbers.

@hexagonrecursion hexagonrecursion marked this pull request as ready for review June 27, 2020 11:08
@anothersimulacrum anothersimulacrum added [JSON] Changes (can be) made in JSON Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Jun 27, 2020
@ZhilkinSerg ZhilkinSerg merged commit d750f3c into CleverRaven:master Jun 30, 2020
@hexagonrecursion hexagonrecursion deleted the modernize-volume-weight branch June 30, 2020 09:19
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