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

Implemented ignoring blank tile #95

Merged
merged 2 commits into from
Aug 12, 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
Binary file modified assets/plugins/plugin-tiled-0.1.5.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.kotcrab.vis.ui.util.Validators;
import com.kotcrab.vis.ui.widget.VisLabel;
import com.kotcrab.vis.ui.widget.VisTable;
import com.kotcrab.vis.ui.widget.VisTextButton;
import com.kotcrab.vis.ui.widget.VisValidatableTextField;
import com.kotcrab.vis.ui.widget.*;
import com.kotcrab.vis.ui.widget.file.FileChooser;
import games.rednblack.h2d.common.H2DDialog;
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
Expand All @@ -21,6 +18,7 @@ public class ImportTileSetDialog extends H2DDialog {
private final InputFileWidget imagePathField;
private final VisTextButton importButton;
private final Facade facade;
private final VisCheckBox removeBlankTileCheck;

public ImportTileSetDialog(Facade facade) {
super("Import TileSet");
Expand All @@ -40,6 +38,8 @@ public ImportTileSetDialog(Facade facade) {
getContentTable().row().padTop(10);
//



Validators.IntegerValidator validator = new Validators.IntegerValidator();

width = StandardWidgetsFactory.createValidableTextField(validator);
Expand All @@ -55,6 +55,13 @@ public ImportTileSetDialog(Facade facade) {
sizeTable.add("px");
getContentTable().add(sizeTable);

//test
getContentTable().row().padTop(10);
removeBlankTileCheck = StandardWidgetsFactory.createCheckBox("Remove blank tile");
getContentTable().add(removeBlankTileCheck);
getContentTable().row().padTop(10);


importButton = StandardWidgetsFactory.createTextButton("Import");
getButtonsTable().add(importButton);
pack();
Expand All @@ -70,6 +77,8 @@ public int getTileHeight() {
return Integer.parseInt(height.getText());
}

public Boolean getBlankTileOption(){ return removeBlankTileCheck.isChecked(); }

private void setListeners() {
importButton.addListener(new ClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,15 @@ private void importTileset(FileHandle tileset) {
for (int y = 0; y < pixmap.getHeight(); y += tileH) {
int w = x + tileW <= pixmap.getWidth() ? tileW : pixmap.getWidth() - x;
int h = y + tileH <= pixmap.getHeight() ? tileH : pixmap.getHeight() - y;
Pixmap tilePixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
tilePixmap.drawPixmap(pixmap, 0, 0, x, y, w, h);

String imagesPath = getCurrentRawImagesPath() + File.separator + name + i + ".png";
FileHandle path = new FileHandle(imagesPath);
PixmapIO.writePNG(path, tilePixmap);

tilePixmap.dispose();
texturePackVO.regions.add(name + i);
i++;
if( getViewComponent().getBlankTileOption()){
if(!isBlankTile(pixmap, x, y, w, h)) { //check if the tile is blank (empty, if not it can be added)
createTilePixmap(pixmap,x,y,w,h,i,name,texturePackVO);
i++;
}
}else{
createTilePixmap(pixmap,x,y,w,h,i,name,texturePackVO);
i++;
}
}
}

Expand All @@ -86,7 +85,32 @@ private void importTileset(FileHandle tileset) {
facade.sendNotification(MsgAPI.ACTION_REPACK);
}

private void createTilePixmap(Pixmap pixmap, int x, int y, int w, int h, int i, String name, TexturePackVO texturePackVO){
Pixmap tilePixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);

//insert control

tilePixmap.drawPixmap(pixmap, 0, 0, x, y, w, h);

int pix = pixmap.getPixel(x,y);
String imagesPath = getCurrentRawImagesPath() + File.separator + name + i + ".png";
FileHandle path = new FileHandle(imagesPath);
PixmapIO.writePNG(path, tilePixmap);

tilePixmap.dispose();
texturePackVO.regions.add(name + i);
}

public String getCurrentRawImagesPath() {
return pluginAPI.getProjectPath() + File.separator + "assets" + File.separator + "orig" + File.separator + "images";
}

private boolean isBlankTile(Pixmap pixmap ,int x, int y, int w, int h){
for(int cx = x; cx < x + w; cx += 1) {
for(int cy = y; cy < y + h; cy += 1 ){
if(pixmap.getPixel(cx, cy)!= 0) return false;
}
}
return true;
}
}
Loading