Include message logging system

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 3 years ago committed by GitHub
parent bf59e5c7c2
commit f56cfc90ac
  1. BIN
      bin/RabiClone.jar
  2. 6
      src/sig/map/Map.java
  3. 38
      src/sig/objects/EditorRenderer.java

Binary file not shown.

@ -73,8 +73,7 @@ public class Map {
return null; return null;
} }
public static void SaveMap(Maps map) { public static void SaveMap(Maps map) throws IOException {
try {
DataOutputStream stream = new DataOutputStream(new FileOutputStream(map.getFile())); DataOutputStream stream = new DataOutputStream(new FileOutputStream(map.getFile()));
saveCharData(stream,map.map.tiles); saveCharData(stream,map.map.tiles);
saveByteData(stream,map.map.views); saveByteData(stream,map.map.views);
@ -82,9 +81,6 @@ public class Map {
saveByteData(stream,map.map.colors); saveByteData(stream,map.map.colors);
saveByteData(stream,map.map.types); saveByteData(stream,map.map.types);
stream.close(); stream.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
private static void saveCharData(DataOutputStream stream, char[] a) throws IOException { private static void saveCharData(DataOutputStream stream, char[] a) throws IOException {

@ -2,6 +2,7 @@ package sig.objects;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.IOException;
import sig.RabiClone; import sig.RabiClone;
import sig.engine.Alpha; import sig.engine.Alpha;
@ -17,12 +18,21 @@ public class EditorRenderer extends LevelRenderer{
Tile selectedTile = Tile.WALL; Tile selectedTile = Tile.WALL;
final StringBuilder tempText = new StringBuilder("Hello World!\n\n Test newlines!\nTest\nTest2\nTest3"); StringBuilder messageLog = new StringBuilder();
int frameCount=0; final static long MESSAGE_TIME = 5000;
StringBuilder frameCheck = new StringBuilder("I am blue! Frame:").append(frameCount); long last_message_log = System.currentTimeMillis();
public EditorRenderer(Panel panel) { public EditorRenderer(Panel panel) {
super(panel); super(panel);
AddMessage("Level editing mode started.");
}
private void AddMessage(String...s) {
messageLog.append('\n');
for (int i=0;i<s.length;i++) {
messageLog.append(s[i]);
}
last_message_log = System.currentTimeMillis();
} }
@Override @Override
@ -45,9 +55,24 @@ public class EditorRenderer extends LevelRenderer{
RabiClone.CURRENT_MAP.ModifyTile(RabiClone.p.highlightedSquare.getX(), RabiClone.p.highlightedSquare.getY(), selectedTile); RabiClone.CURRENT_MAP.ModifyTile(RabiClone.p.highlightedSquare.getX(), RabiClone.p.highlightedSquare.getY(), selectedTile);
} }
if(KeyHeld(KeyEvent.VK_CONTROL)&&KeyHeld(KeyEvent.VK_S)){ if(KeyHeld(KeyEvent.VK_CONTROL)&&KeyHeld(KeyEvent.VK_S)){
System.out.println("Saving map"); AddMessage("Saving map...");
try {
Map.SaveMap(RabiClone.CURRENT_MAP); Map.SaveMap(RabiClone.CURRENT_MAP);
System.out.println("Map saved"); AddMessage(RabiClone.CURRENT_MAP.toString()," has been saved successfully.");
} catch (IOException e) {
e.printStackTrace();
AddMessage("Map failed to save: ",e.getLocalizedMessage());
}
}
updateMessageLog();
}
private void updateMessageLog() {
if (messageLog.length()>0) {
if (System.currentTimeMillis()-last_message_log>MESSAGE_TIME) {
last_message_log=System.currentTimeMillis();
messageLog.replace(messageLog.indexOf("\n"), messageLog.indexOf("\n",messageLog.indexOf("\n")), "");
}
} }
} }
@ -64,8 +89,7 @@ public class EditorRenderer extends LevelRenderer{
@Override @Override
public void draw(byte[] p) { public void draw(byte[] p) {
super.draw(p); super.draw(p);
Draw_Text(32,16,tempText,Font.PROFONT_12); Draw_Text(4,0,messageLog,Font.PROFONT_12);
Draw_Text_Ext(104,137,new StringBuilder("I am blue! Frame:").append(frameCount++),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.SLATE_BLUE);
} }
@Override @Override

Loading…
Cancel
Save