QnD support .imc saving
use external artgaphics-0.1.0.jar (part of sharedrawweb project ) savec .imc files
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
PACKAGE=org.artisanlogiciel.games
|
PACKAGE=org.artisanlogiciel.games
|
||||||
PACKAGE_DIR=$(subst .,/,$(PACKAGE))
|
PACKAGE_DIR=$(subst .,/,$(PACKAGE))
|
||||||
OUT=out
|
OUT=out
|
||||||
|
# external libraries
|
||||||
|
LIBS=../libs/artgaphics-0.1.0.jar
|
||||||
EDITOR=emacs
|
EDITOR=emacs
|
||||||
|
|
||||||
$(OUT):
|
$(OUT):
|
||||||
@@ -11,21 +13,21 @@ clean:
|
|||||||
@find $(OUT) -name "*.class" -type f -print0|xargs -0 rm 2>/dev/null || echo "nothing to clean"
|
@find $(OUT) -name "*.class" -type f -print0|xargs -0 rm 2>/dev/null || echo "nothing to clean"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
javac -d $(OUT) $(PACKAGE_DIR)/LabyModel.java
|
javac -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/LabyModel.java
|
||||||
javac -d $(OUT) $(PACKAGE_DIR)/Main.java
|
javac -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/Main.java
|
||||||
java -cp $(OUT) $(PACKAGE).Main
|
java -cp $(OUT) $(PACKAGE).Main
|
||||||
|
|
||||||
|
|
||||||
run/%: $(OUT)
|
run/%: $(OUT)
|
||||||
javac -d $(OUT) $(PACKAGE_DIR)/$(subst run/,,$@).java
|
javac -cp $(LIBS):$(OUT) -d $(OUT) $(PACKAGE_DIR)/$(subst run/,,$@).java
|
||||||
java -cp $(OUT) $(PACKAGE)/$(subst run/,,$@)
|
java -cp $(OUT):$(LIBS) $(PACKAGE)/$(subst run/,,$@)
|
||||||
|
|
||||||
display: run/Display
|
display: run/Display
|
||||||
|
|
||||||
|
|
||||||
display/%: $(OUT)
|
display/%: $(OUT)
|
||||||
javac -d $(OUT) $(PACKAGE_DIR)/Display.java
|
javac -cp $(LIBS) -d $(OUT) $(PACKAGE_DIR)/Display.java
|
||||||
java -cp $(OUT) $(PACKAGE).Display $(subst display/,,$@)
|
java -cp $(OUT):$(LIBS) $(PACKAGE).Display $(subst display/,,$@)
|
||||||
|
|
||||||
compile/%:
|
compile/%:
|
||||||
javac -d $(OUT) $(PACKAGE_DIR)/$(subst compile/,,$@).java
|
javac -d $(OUT) $(PACKAGE_DIR)/$(subst compile/,,$@).java
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.awt.Container;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
@@ -15,6 +16,7 @@ import java.awt.event.ComponentEvent;
|
|||||||
import java.awt.event.InputEvent;
|
import java.awt.event.InputEvent;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseMotionListener;
|
import java.awt.event.MouseMotionListener;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -44,6 +46,9 @@ import javax.swing.event.ChangeListener;
|
|||||||
import org.artisanlogiciel.games.stl.Wall3d;
|
import org.artisanlogiciel.games.stl.Wall3d;
|
||||||
import org.artisanlogiciel.util.UTF8Control;
|
import org.artisanlogiciel.util.UTF8Control;
|
||||||
|
|
||||||
|
import org.artisanlogiciel.graphics.Drawing;
|
||||||
|
import org.artisanlogiciel.graphics.DrawingLine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display is Main JFrame for this tool
|
* Display is Main JFrame for this tool
|
||||||
**/
|
**/
|
||||||
@@ -62,6 +67,8 @@ public class Display extends JFrame
|
|||||||
|
|
||||||
MazeParams params = null;
|
MazeParams params = null;
|
||||||
|
|
||||||
|
Drawing drawing = new Drawing();
|
||||||
|
|
||||||
Display(LabyModel model,int W, int H, MazeParams params)
|
Display(LabyModel model,int W, int H, MazeParams params)
|
||||||
{
|
{
|
||||||
super(labels.getString("title"));
|
super(labels.getString("title"));
|
||||||
@@ -190,6 +197,82 @@ public class Display extends JFrame
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addWallInDrawing(int pX, int pY, Drawing d)
|
||||||
|
{
|
||||||
|
short walls = model.getWalls(pX,pY);
|
||||||
|
// todo
|
||||||
|
int w = 2;
|
||||||
|
int h = 2;
|
||||||
|
int ox=0;
|
||||||
|
int oy=0;
|
||||||
|
|
||||||
|
int x = ox + (int) (pX * w);
|
||||||
|
int y = oy + (int) (pY * h);
|
||||||
|
DrawingLine dl = new DrawingLine();
|
||||||
|
if ( (pY == 0) && ((walls & Brick.UP) == Brick.UP))
|
||||||
|
{
|
||||||
|
dl.addPoint(new Point(x, y));
|
||||||
|
dl.addPoint(new Point(x + (int) w, y));
|
||||||
|
}
|
||||||
|
if ((walls & Brick.DOWN) == Brick.DOWN)
|
||||||
|
{
|
||||||
|
dl.addPoint(new Point(x, y + (int) h));
|
||||||
|
dl.addPoint(new Point(x + (int) w, y + (int) h));
|
||||||
|
}
|
||||||
|
if ((walls & Brick.RIGHT) == Brick.RIGHT)
|
||||||
|
{
|
||||||
|
dl.addPoint(new Point(x + (int) w, y));
|
||||||
|
dl.addPoint(new Point(x + (int) w, y + (int) h));
|
||||||
|
}
|
||||||
|
if ( (pX == 0 ) && ((walls & Brick.LEFT) == Brick.LEFT))
|
||||||
|
{
|
||||||
|
dl.addPoint(new Point(x, y));
|
||||||
|
dl.addPoint(new Point(x, y + (int) h));
|
||||||
|
}
|
||||||
|
d.addLine(dl);
|
||||||
|
}
|
||||||
|
|
||||||
|
Drawing createDrawing()
|
||||||
|
{
|
||||||
|
Drawing d = new Drawing();
|
||||||
|
{
|
||||||
|
short walls;
|
||||||
|
|
||||||
|
// draw all walls within clip bounds horiz first then lines
|
||||||
|
for (int y = 0; y < model.getHeight(); y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < model.getWidth(); x ++)
|
||||||
|
{
|
||||||
|
addWallInDrawing(x,y,d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveImc()
|
||||||
|
{
|
||||||
|
Drawing d = createDrawing();
|
||||||
|
|
||||||
|
if ( d != null )
|
||||||
|
{
|
||||||
|
File outfile = new File(params.getSaveDir(), params.getName() + ".imc");
|
||||||
|
System.out.println("Saving to " + outfile + " ...");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DataOutputStream out = new DataOutputStream(new FileOutputStream(outfile));
|
||||||
|
d.saveLinesKompressed(out);
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
System.out.println("... Done.");
|
||||||
|
}
|
||||||
|
catch (IOException io)
|
||||||
|
{
|
||||||
|
io.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void savePng()
|
void savePng()
|
||||||
{
|
{
|
||||||
File file = new File("snapshot.png");
|
File file = new File("snapshot.png");
|
||||||
@@ -475,6 +558,21 @@ public class Display extends JFrame
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
saveButton.addActionListener(saveAction);
|
saveButton.addActionListener(saveAction);
|
||||||
|
final JButton saveImcButton = new JButton(labels.getString("save") +" imc");
|
||||||
|
Action saveImcAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent evt)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
System.out.println("save imc");
|
||||||
|
/*
|
||||||
|
MazeParamsFixed p = (MazeParamsFixed) params;
|
||||||
|
p.setName(saveName.getText());
|
||||||
|
save(p,model);
|
||||||
|
*/
|
||||||
|
saveImc();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
saveImcButton.addActionListener(saveImcAction);
|
||||||
|
|
||||||
final JButton quitButton = new JButton(labels.getString("quit"));
|
final JButton quitButton = new JButton(labels.getString("quit"));
|
||||||
Action quitAction = new AbstractAction() {
|
Action quitAction = new AbstractAction() {
|
||||||
@@ -494,6 +592,7 @@ public class Display extends JFrame
|
|||||||
resizecontrol.add(saveName);
|
resizecontrol.add(saveName);
|
||||||
resizecontrol.add(savePngButton);
|
resizecontrol.add(savePngButton);
|
||||||
resizecontrol.add(saveButton);
|
resizecontrol.add(saveButton);
|
||||||
|
resizecontrol.add(saveImcButton);
|
||||||
resizecontrol.add(quitButton);
|
resizecontrol.add(quitButton);
|
||||||
|
|
||||||
add(controlDisplayPanel, BorderLayout.SOUTH);
|
add(controlDisplayPanel, BorderLayout.SOUTH);
|
||||||
|
|||||||
Reference in New Issue
Block a user