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

ci: Add a Github Action to automatically generate and update sounds.json #31

Merged
merged 1 commit into from
Jul 30, 2024
Merged
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
34 changes: 34 additions & 0 deletions .github/workflows/generate-sounds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Generate sounds.json

on:
workflow_dispatch:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
merge_group:
branches: [main, development]

jobs:
generate-sounds:
if: '!github.event.pull_request.draft'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout the Repository
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Generate sounds.json
run: |
chmod +x ./utils/process_sounds.sh
./utils/process_sounds.sh ./src/main/resources/assets/wynnvp/sounds.json

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_user_name: 'VoWBot'
commit_user_email: '[email protected]'
commit_message: 'ci: generate sounds.json'
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ allprojects {
}
json {
target "src/**/*.json"
targetExclude "src/**/sound_info.json"
targetExclude "src/**/sound_info.json", "src/**/sounds.json"
gson()
.indentWithSpaces(2)
.sortByKeys()
Expand Down
64 changes: 64 additions & 0 deletions utils/process_sounds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

# This script processes the sound_info.json file and creates a sounds.json file,
# which is used by Minecraft to load and play sounds.

# Check if the sound_info.json file is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 path/to/sound_info.json"
exit 1
fi

sound_info_file=$1

# Check if the provided file exists
if [ ! -f "$sound_info_file" ]; then
echo "File not found: $sound_info_file"
exit 1
fi

# Get the directory of the provided sound_info.json file
sound_info_dir=$(dirname "$sound_info_file")

# Define the output sounds.json file path
sounds_json_file="$sound_info_dir/sounds.json"

# Process the sound_info.json file and create the sounds.json file
# NOTE: This script can only generate the fileOverride field for the sounds.json file,
# if the NPC name and line info are provided in the sound_info.json file.
# If either of these data is not available, the script fails. Use a unique fileOverride value for these cases.
jq '[
.content | to_entries | map(
.key as $content | .value.contexts | to_entries | map(
.key as $context | .value.dialogues | map(
.fileOverride as $fileOverride |
{
"fileName": ($fileOverride // (
($content | gsub("[^a-zA-Z0-9]"; "") | ascii_downcase) + "-" +
($context | gsub("[^a-zA-Z0-9]"; "") | ascii_downcase) + "-" +
(.lineInfo.npc | gsub("[^a-zA-Z0-9]"; "") | ascii_downcase) + "-" +
(.lineInfo.line.current | tostring)
))
} | {
(.fileName): {
"category": "voice",
"sounds": [
{
"name": "wynnvp:\(.fileName)",
"stream": true
}
]
}
}
)
)
) | flatten | add
] | add | to_entries | sort_by(.key) | from_entries' "$sound_info_file" > "$sounds_json_file"

# Check if the sounds.json file was created successfully
if [ $? -eq 0 ]; then
echo "sounds.json file has been created successfully at $sounds_json_file"
else
echo "An error occurred while creating the sounds.json file"
exit 1
fi
Loading