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

Allow loading TMX maps from jars in libtiled-java #2829

Merged
merged 5 commits into from
Jun 16, 2020
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
5 changes: 5 additions & 0 deletions util/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
6 changes: 0 additions & 6 deletions util/java/libtiled-java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ dependency-reduced-pom.xml
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
Expand Down
48 changes: 47 additions & 1 deletion util/java/libtiled-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,55 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<executable>jar</executable>
<workingDirectory>target/generated-test-resources</workingDirectory>
<arguments>
<argument>cf</argument>
<argument>resources.jar</argument>
<argument>-C</argument>
<argument>../../src/test/resources</argument>
<argument>.</argument>
</arguments>
</configuration>
<executions>
<execution>
<id>jar-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>add-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>target/generated-test-resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>java-11-profile</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Copyright (C) 2004 - 2019 Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
* Copyright (C) 2004 - 2019 Adam Turk <aturk@biggeruniverse.com>
* Copyright (C) 2016 - 2019 Mike Thomas <mikepthomas@outlook.com>
* Copyright (C) 2020 Adam Hornacek <adam.hornacek@icloud.com>
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -37,6 +38,7 @@
import java.awt.image.FilteredImageSource;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -94,13 +96,23 @@ public TileSet() {
* @see TileSet#importTileBitmap(BufferedImage, TileCutter)
* @throws java.io.IOException if any.
*/
public void importTileBitmap(String imgFilename, TileCutter cutter)
throws IOException {
public void importTileBitmap(String imgFilename, TileCutter cutter) throws IOException {
setTilesetImageFilename(imgFilename);
importTileBitmap(new File(imgFilename).toURI().toURL(), cutter);
}

Image image = ImageIO.read(new File(imgFilename));
/**
* Creates a tileset from a tileset image file.
*
* @param imgUrl an url to the tileset image
* @param cutter a {@link org.mapeditor.util.TileCutter} object.
* @see TileSet#importTileBitmap(BufferedImage, TileCutter)
* @throws java.io.IOException if any.
*/
public void importTileBitmap(final URL imgUrl, final TileCutter cutter) throws IOException {
Image image = ImageIO.read(imgUrl);
if (image == null) {
throw new IOException("Failed to load " + tilebmpFile);
throw new IOException("Failed to load " + imgUrl);
}

Toolkit tk = Toolkit.getDefaultToolkit();
Expand Down
Loading