henkelmax / audio-player

Put your own audio files on music discs!
58 stars 20 forks source link

Feature: filename Subcommand #74

Closed BJTMastermind closed 6 months ago

BJTMastermind commented 6 months ago

This pull request introduces a new filename subcommand to /audioplayer.

Overview

It operates by utilizing a new file named filename_mappings.dat, which resides in the existing audio_player_data folder of the world. This file is structured as a GZipped NBT file, containing a list of mappings between original filenames and their corresponding UUID names.

File Structure

The structure of filename_mappings.dat is as follows:

TAG_Compound(): {
    TAG_List("mappings"): {
        TAG_Compound(): {
            TAG_String("filename"): "<Original filename>.<extension>",
            TAG_String("uuid"): "<UUID>.<extension>"
        },
        ...
    }
}

Functionality

Whenever a new audio file is uploaded, regardless of the method used, an entry is added to filename_mappings.dat. Conversely, if a file is deleted the mappings associated with that file will be removed the next time the filename command is ran or when another audio file is uploaded.

Motivation

I implemented this feature to enhance the usability and maintainability of the users audio files. By introducing the filename subcommand and associated functionality, users can easily manage audio file mappings, whether its with the command itself for a couple of files or externally with user made scripts for a larger number of files.

BJTMastermind commented 6 months ago

This should be good now.

henkelmax commented 6 months ago

Also please explain me what's the purpose of this command? It basically just allows you to get the file name of a custom sound item. It can't be used anywhere, so I don't really see a point of this at all.

henkelmax commented 6 months ago

35883d6c4b50fd0d6a2a8d5f0067084ed7aab980 should properly implement file names that can be actually used for applying them to items.

BJTMastermind commented 6 months ago

I apologize that the code is a little messy.

This is the first time im contributing to a project so im sure there's a lot for me to learn in making better contributions and code in general.

The main feature from this I would have used is the nbt file database as I was recently converting a world that used this mod for custom audio to bedrock edition and since all the sounds are just uuids it makes it hard to know whats what, so the database of mappings would allow me to setup a script to rename them to their original uploaded name to better know what the files are just by the name, this is most helpful when there are a lot of audio files.

I added the filename command along with it for when there are only a few audio files the command could be used to copy the original name and rename the file based on it id from the id command. but I can see from an in game point of view this command doesn't do much.

I thought about maybe having the file name be the default display if you don't give the item one but i figured that some might want it to be blank so i didn't end up do this.

henkelmax commented 6 months ago

I apologize that the code is a little messy.

This is the first time im contributing to a project so im sure there's a lot for me to learn in making better contributions and code in general.

No worries.

Basically how I implemented it, is pretty similar. The file names are stored in a json, which is also more human readable as NBT. Theres also a command that gives you the file name of an item and additionally lets you apply audio to an item by file name.

BJTMastermind commented 6 months ago

I was just checking it out. Looks great! I did noticed the apply command that pops up when you click [Put on item] might be broken a bit as it was given me the error No audio with name '<uuid>' found or more then one found but when I used the musicdisc command instead I was able to apply the sound to the disc.

henkelmax commented 6 months ago

That's not happening for me. Are you sure, you tried the latest commit?

BJTMastermind commented 6 months ago

Yeah its on the latest commit. I could make a bug report to give more detail about it and maybe a short clip of running the commands. If thats easier for you.

henkelmax commented 6 months ago

You can post that here. I'll also do some testing.

BJTMastermind commented 6 months ago

https://youtu.be/LzArcTJaBtU The test i did here is before the audio_player_data folder is generated. I used the filebin command here because i had already setup the download before with upload but same thing happens when using upload

henkelmax commented 6 months ago

Thanks, that might be an issue that doesn't happen in my development environment.

henkelmax commented 6 months ago

Can you try if it works for you now?

BJTMastermind commented 6 months ago

Looks to be working now.

henkelmax commented 6 months ago

Alright, thanks for testing that out!