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

Feat/litematic support #233

Merged
merged 14 commits into from
Dec 22, 2023
Merged

Feat/litematic support #233

merged 14 commits into from
Dec 22, 2023

Conversation

KevinDaGame
Copy link
Owner

@KevinDaGame KevinDaGame commented Dec 16, 2023

What type of PR is this? (check all applicable)

  • Feature
  • Refactor
  • Bug Fix
  • Optimization
  • Documentation Update

Description

close #232

  • Implement litematic support. Thanks @SandroHc!
  • Refactor stencil/schematic system to support litematica and any future formats.
  • Removed check for .schem files. In the future, we might want to keep a list with supported formats (preferably directly from schematic4J)
  • Added Unittests! the VoxelSchematicLoader has 100% test coverage
  • DataFolderSchematicReader can't be properly tested due to it's dependency on the file system
  • In the future we could add any number of schematic readers, such as one over the network (who knows?)

QA Instructions, Screenshots, Recordings

The following schematics can be used for testing:
schematics.zip

Added/updated tests?

  • Yes
  • No, and this is why: please replace this line with details on why tests
    have not been included
  • I need help with writing tests
  • Not needed

[optional] What gif best describes this PR or how it makes you feel?

alt_text

@KevinDaGame KevinDaGame added enhancement New feature or request Common All versions labels Dec 16, 2023
@KevinDaGame KevinDaGame self-assigned this Dec 16, 2023
class DataFolderSchematicReader : ISchematicReader {
override fun getSchematicFile(name: String): File? {
//check for exact name
val exactSchematic = VoxelSniper.voxelsniper.fileHandler.getDataFile(SCHEMATIC_FILE_ROOT_PATH + name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is better to use new File(baseDirectory, file); or simular.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I disagree. Until now we have used the file handler everywhere. Making a file directly would require getting the full path to the plugin root, which is extra work

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also I am not sure if using '/' is platform dependent or not..

Copy link
Owner Author

Choose a reason for hiding this comment

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

you don't https://github.com/KevinDaGame/VoxelSniper-Reimagined/blob/master/VoxelSniperCore/src/main/java/com/github/kevindagame/util/Messages.java#L383C92-L383C92

That's more an issue on that part. I prefer to leave this file logic to the main file handler. It might be a good idea to refactor this in other places

Copy link
Collaborator

@Lennart99 Lennart99 Dec 19, 2023

Choose a reason for hiding this comment

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

Maybe this would be a nice option, we could add/change a method in filehandler File getDataFile(String... path), which could take all path 'parts', without having to concatenate the strings, which I think is not the way it is meant to be done in Java (could be wrong here, but most examples either use File or Paths).

    default File getDataFile(String... path) {
        File f = getDataFolder();
        for (String p : path) {
            f = new File(f, p);
        }
        return f;
    }

Copy link
Owner Author

Choose a reason for hiding this comment

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

INFO: Why don't you like the way I'm using it? I'd like to stay away from the File constructor wherever possible, to prevent divergence later on.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I do think though that the way we access the filehandler isn't nice. Perhabs this could be solved using dependency injection

Copy link
Collaborator

@Lennart99 Lennart99 Dec 19, 2023

Choose a reason for hiding this comment

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

I will approve the PR, since the same issue was already present before I think, but we should indeed look into improving this.
I feel like we should, if we want to be able to change the implementation, supply every part of the path to the filehandler separately, so that it can traverse the filesystem in whatever way it needs to.

…ception. (This is a failsafe. Ideally this shouldn't happen at all)
@SandroHc
Copy link

In the future, we might want to keep a list with supported formats (preferably directly from schematic4J)

That can already be done like this:

Set<String> supportedExtensions = new HashSet<>();
for (SchematicFormat format : SchematicFormat.values()) {
	supportedExtensions.add(format.fileExtension);
}

// Or as a one-liner:
Set<String> supportedExtensions = Arrays.stream(SchematicFormat.values())
    .map(f -> f.fileExtension)
    .collect(Collectors.toSet());

@KevinDaGame KevinDaGame merged commit ce5f286 into master Dec 22, 2023
1 check passed
@KevinDaGame KevinDaGame deleted the feat/litematic_support branch December 22, 2023 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Common All versions enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Litematic support for stencils
3 participants