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

Rework Track/TrackSet management #65

Merged
merged 1 commit into from
Oct 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
19 changes: 7 additions & 12 deletions editor/src/main/java/org/moparforia/editor/EditorPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.moparforia.editor;

import org.moparforia.shared.Track;
import org.moparforia.shared.tracks.Track;
import org.moparforia.shared.tracks.TrackCategory;

import javax.swing.*;
import javax.swing.border.Border;
Expand Down Expand Up @@ -207,7 +208,7 @@ public void actionPerformed(ActionEvent e) {
chooser.showDialog(getThis(),"hurr");
File f = chooser.getSelectedFile();
//currentTrack = TrackStore.getTrack(f);//todo get rid of this (uses org.moparforia.server.track.TrackStore)!!
currentTrack = TrackEditor.loadTrack(f);
currentTrack = TrackEditor.loadTrack(f.toPath());
Map m = new MapDecompressor().decompress(currentTrack.getMap());
canvas.setMap(m);
} catch (Exception exp) {
Expand All @@ -227,10 +228,8 @@ public void actionPerformed(ActionEvent e) {
if(currentTrack == null) {
String data = new MapCompressor().compress(canvas.getMap());
String name = JOptionPane.showInputDialog(getThis(),"WUTS THE NAME OF THIS TRACK?");
Copy link
Owner

Choose a reason for hiding this comment

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

xD

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Editor is a magical place :D

Track t = new Track(name, "fc", data, 7,
new int[]{1000, 1000, 2, 10}, new String[]{"fc", "sum cunt"}, new long[]{10, 3300000},
new int[]{0, 0, 0, 0, 3, 0, 0, 0, 0, 10, 10});
currentTrack = t;
Track track = new Track(name, "fc", data, TrackCategory.UNKNOWN);
currentTrack = track;
}

MapCompressor mc = new MapCompressor();
Expand All @@ -240,13 +239,9 @@ public void actionPerformed(ActionEvent e) {
String save = currentTrack.toString().replace("\t", "\n");
File file = new File("tracks/custom/" + currentTrack.getName() + ".track");

PrintStream out = null;
try {
out = new PrintStream(new FileOutputStream(file, false));
try (PrintStream out = new PrintStream(new FileOutputStream(file, false))) {
out.print(save);
} catch (Exception ee) {
} finally {
if (out != null) out.close();
} catch (Exception ignored) {
}

}
Expand Down
40 changes: 14 additions & 26 deletions editor/src/main/java/org/moparforia/editor/TrackEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package org.moparforia.editor;

import org.moparforia.shared.Track;
import org.moparforia.shared.tracks.Track;
import org.moparforia.shared.tracks.TrackCategory;
import org.moparforia.shared.tracks.filesystem.FileSystemTrackManager;
import org.moparforia.shared.tracks.filesystem.TrackFileParser;

import javax.swing.*;
import javax.swing.border.TitledBorder;
Expand All @@ -15,6 +18,7 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.*;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Scanner;

Expand Down Expand Up @@ -185,25 +189,9 @@ private void generateButtons() {
togglePencil.setSelected(true);
}

public static final Track loadTrack(File f) throws IOException {

String name = null, author = null, data = null;
Scanner scanner = new Scanner(new FileInputStream(f));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.startsWith("V ")) {
// hi
} else if (line.startsWith("S ")) {
// hi? get on it, watson
} else if (line.startsWith("A ")) {
author = line.substring(2);
} else if (line.startsWith("N ")) {
name = line.substring(2);
} else if (line.startsWith("T ")) {
data = line.substring(2);
}
}
return new Track(name, author, data, 7);
public static final Track loadTrack(Path path) throws IOException {

return TrackFileParser.parseTrack(path, TrackCategory.UNKNOWN);
}

private void menuNewActionPerformed(ActionEvent e) {
Expand All @@ -216,9 +204,9 @@ private void menuOpenActionPerformed(ActionEvent e) {
int result = chooser.showOpenDialog(this);
if (result != JFileChooser.CANCEL_OPTION) {
File f = chooser.getSelectedFile();
Track currentTrack = loadTrack(f);
Track currentTrack = loadTrack(f.toPath());
Map m = new MapDecompressor().decompress(currentTrack.getMap());
mapCanvas.updateProperties(currentTrack.getName(), currentTrack.getCategory());
mapCanvas.updateProperties(currentTrack.getName(), currentTrack.getCategory().getId());
mapCanvas.setMap(m);
}
} catch (Exception exp) {
Expand All @@ -241,7 +229,7 @@ private void menuSaveActionPerformed(ActionEvent e) {
return;
}
String data = new MapCompressor().compress(mapCanvas.getMap());
Track t = new Track(mapCanvas.getTrackName(), "editor", data, 7);
Track track = new Track(mapCanvas.getTrackName(), "editor", data, TrackCategory.UNKNOWN);

JFileChooser saver = new JFileChooser("tracks/custom/");
saver.setFileFilter(new FileFilter() {
Expand All @@ -255,13 +243,13 @@ public String getDescription() {
return "*.track";
}
});
saver.setSelectedFile(new File(t.getName().replaceAll(" ", "_")));
saver.setSelectedFile(new File(track.getName().replaceAll(" ", "_")));
int result = saver.showSaveDialog(this);

if (result == JFileChooser.CANCEL_OPTION) return;

t.setMap(data);
String save = t.toSaveString().replace("\t", "\n");
track.setMap(data);
String save = FileSystemTrackManager.convertTrack(track).replace("\t", "\n");

PrintStream out = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.moparforia.editor;

import org.moparforia.shared.tracks.TrackCategory;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
Expand All @@ -26,7 +28,7 @@ public TrackPropertiesDialog(Dialog owner) {

private void loadValues() {
textTrackName.setText(((TrackEditor)getOwner()).getMapCanvas().getTrackName());
comboTrackCategory.setSelectedIndex(((TrackEditor)getOwner()).getMapCanvas().getTrackCategory() - 1);
comboTrackCategory.setSelectedIndex(TrackCategory.BASIC.getId());
}

private void okButtonActionPerformed(ActionEvent e) {
Expand Down
22 changes: 12 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@
<version>3.10.6.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.moparforia</groupId>
<artifactId>shared</artifactId>
Expand Down Expand Up @@ -137,6 +127,18 @@
<version>3.5.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.marschall</groupId>
<artifactId>memoryfilesystem</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.softsmithy.lib</groupId>
<artifactId>softsmithy-lib-core</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
8 changes: 0 additions & 8 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
<artifactId>netty</artifactId> <!-- Use 'netty-all' for 4.0 or above -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
</dependency>
<dependency>
<groupId>org.moparforia</groupId>
<artifactId>shared</artifactId>
Expand Down
7 changes: 1 addition & 6 deletions server/server.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: io.netty:netty:3.6.6.Final" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.6.0" level="project" />
<orderEntry type="library" name="Maven: org.mongodb.morphia:morphia:1.2.2" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:2.2.2" level="project" />
<orderEntry type="library" name="Maven: com.thoughtworks.proxytoys:proxytoys:1.0" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty:3.10.6.Final" level="project" />
<orderEntry type="module" module-name="shared" />
<orderEntry type="library" name="Maven: info.picocli:picocli:4.5.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.6.2" level="project" />
Expand All @@ -29,6 +25,5 @@
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.10.13" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-junit-jupiter:3.5.10" level="project" />
<orderEntry type="module" module-name="client" scope="TEST" />
</component>
</module>
10 changes: 6 additions & 4 deletions server/src/main/java/org/moparforia/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.moparforia.server.game.LobbyType;
import org.moparforia.server.game.Player;
import org.moparforia.server.net.*;
import org.moparforia.server.track.TrackManager;
import org.moparforia.shared.tracks.TrackLoadException;
import org.moparforia.shared.tracks.filesystem.FileSystemTrackManager;
import org.moparforia.shared.tracks.filesystem.FileSystemStatsManager;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -152,10 +154,10 @@ public void addPlayer(Player p) {
}

public void start() {
//TrackStore.LoadTracks(); // gr8 piece of engineering right here!
try {
new TrackManager().load();
} catch (IOException e) {
FileSystemTrackManager.getInstance().load();
FileSystemStatsManager.getInstance().load();
} catch (TrackLoadException | IOException e) {
System.err.println("Unable to load tracks: " + e.getMessage());
e.printStackTrace();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//import org.mongodb.morphia.Datastore;
//import org.mongodb.morphia.Morphia;
//import org.moparforia.server.util.SHA1;
//import org.moparforia.shared.Track;
//import org.moparforia.shared.tracks.Track;
//
///**
// * User: Johan
Expand Down
Loading