Begin implementation of data tiles with extra value storage

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 2 years ago
parent 65d7ed8cce
commit b1919b54d4
  1. 2
      README.md
  2. BIN
      bin/controls.config
  3. BIN
      maps/world1.map
  4. 14
      src/sig/engine/Action.java
  5. 46
      src/sig/engine/String.java
  6. 30
      src/sig/map/Map.java
  7. 13
      src/sig/map/Maps.java
  8. 15
      src/sig/objects/ConfigureControls.java
  9. 48
      src/sig/objects/EditorRenderer.java
  10. 2
      src/sig/objects/LevelRenderer.java

@ -55,7 +55,7 @@ https://docs.oracle.com/en/java/javase/14/jpackage/image-and-runtime-modificatio
`fallthrough` to suppress warnings relative to missing breaks in switch statements `fallthrough` to suppress warnings relative to missing breaks in switch statements
`finally` to suppress warnings relative to finally block that don’t return `finally` to suppress warnings relative to finally block that don’t return
`hiding` to suppress warnings relative to locals that hide variable `hiding` to suppress warnings relative to locals that hide variable
`incomplete`-switch to suppress warnings relative to missing entries in a switch statement (enum case) `incomplete-switch` to suppress warnings relative to missing entries in a switch statement (enum case)
`nls` to suppress warnings relative to non-nls string literals `nls` to suppress warnings relative to non-nls string literals
`null` to suppress warnings relative to null analysis `null` to suppress warnings relative to null analysis
`restriction` to suppress warnings relative to usage of discouraged or forbidden references `restriction` to suppress warnings relative to usage of discouraged or forbidden references

Binary file not shown.

Binary file not shown.

@ -17,7 +17,19 @@ public enum Action {
PLAY_GAME(new KeyBind(KeyEvent.VK_F1)), PLAY_GAME(new KeyBind(KeyEvent.VK_F1)),
EDITOR_SET_VIEW(new KeyBind(KeyEvent.VK_F3)), EDITOR_SET_VIEW(new KeyBind(KeyEvent.VK_F3)),
EDITOR_SET_TYPE(new KeyBind(KeyEvent.VK_F4)), EDITOR_SET_TYPE(new KeyBind(KeyEvent.VK_F4)),
EDITOR_SET_BACKGROUND(new KeyBind(KeyEvent.VK_F5)),; EDITOR_SET_BACKGROUND(new KeyBind(KeyEvent.VK_F5)),
_1(new KeyBind(KeyEvent.VK_1),new KeyBind(KeyEvent.VK_NUMPAD1)),
_2(new KeyBind(KeyEvent.VK_2),new KeyBind(KeyEvent.VK_NUMPAD2)),
_3(new KeyBind(KeyEvent.VK_3),new KeyBind(KeyEvent.VK_NUMPAD3)),
_4(new KeyBind(KeyEvent.VK_4),new KeyBind(KeyEvent.VK_NUMPAD4)),
_5(new KeyBind(KeyEvent.VK_5),new KeyBind(KeyEvent.VK_NUMPAD5)),
_6(new KeyBind(KeyEvent.VK_6),new KeyBind(KeyEvent.VK_NUMPAD6)),
_7(new KeyBind(KeyEvent.VK_7),new KeyBind(KeyEvent.VK_NUMPAD7)),
_8(new KeyBind(KeyEvent.VK_8),new KeyBind(KeyEvent.VK_NUMPAD8)),
_9(new KeyBind(KeyEvent.VK_9),new KeyBind(KeyEvent.VK_NUMPAD9)),
_0(new KeyBind(KeyEvent.VK_0),new KeyBind(KeyEvent.VK_NUMPAD0)),
BACKSPACE(new KeyBind(KeyEvent.VK_BACK_SPACE)),
ENTER(new KeyBind(KeyEvent.VK_ENTER));
float val; float val;
Key controllingKey; Key controllingKey;

@ -114,6 +114,52 @@ public class String{
updateBounds(this.sb.toString()); updateBounds(this.sb.toString());
return this; return this;
} }
/**
* Returns a new {@code String} that contains a subsequence of
* characters currently contained in this character sequence. The
* substring begins at the specified index and extends to the end of
* this sequence.
*
* @param start The beginning index, inclusive.
* @return The new string.
* @throws StringIndexOutOfBoundsException if {@code start} is
* less than zero, or greater than the length of this object.
*/
public String substring(int start) {
java.lang.String cutString = this.sb.substring(start);
clear();
this.sb.append(cutString);
bounds = new Point(0,1);
currentLineWidth=0;
updateBounds(this.sb.toString());
return this;
}
/**
* Returns a new {@code String} that contains a subsequence of
* characters currently contained in this sequence. The
* substring begins at the specified {@code start} and
* extends to the character at index {@code end - 1}.
*
* @param start The beginning index, inclusive.
* @param end The ending index, exclusive.
* @return The new string.
* @throws StringIndexOutOfBoundsException if {@code start}
* or {@code end} are negative or greater than
* {@code length()}, or {@code start} is
* greater than {@code end}.
*/
public String substring(int start,int end) {
java.lang.String cutString = this.sb.substring(start,end);
clear();
this.sb.append(cutString);
bounds = new Point(0,1);
currentLineWidth=0;
updateBounds(this.sb.toString());
return this;
}
public int length() { public int length() {
return this.sb.length(); return this.sb.length();
} }

@ -230,17 +230,31 @@ public class Map {
} }
public void ModifyDataTile(int x,int y,DataTile t) { public void ModifyDataTile(int x,int y,DataTile t) {
DataTile prevTile = DataTile.values()[data[y*Map.MAP_WIDTH+x]]; if (data[y*Map.MAP_WIDTH+x]<32768) {
if (prevTile.ordinal()==0) { DataTile prevTile = DataTile.values()[data[y*Map.MAP_WIDTH+x]];
eventTileCount++; if (prevTile.ordinal()==0) {
} eventTileCount++;
if (t.ordinal()==0) { }
if (t.ordinal()==0) {
eventTileCount--;
}
data[y*Map.MAP_WIDTH+x]=(char)(t.ordinal());
} else {
eventTileCount--; eventTileCount--;
data[y*Map.MAP_WIDTH+x]=(char)(t.ordinal());
} }
data[y*Map.MAP_WIDTH+x]=(char)(t.ordinal());
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+"."); //System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");
} }
public void ModifyDataTile(int x, int y, char value) {
eventTileCount++;
if (value>32767) {
value=32767;
}
data[y*Map.MAP_WIDTH+x]=(char)(value+32768);
System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+data[y*MAP_WIDTH+x]+".");
}
public char getWaterLevel() { public char getWaterLevel() {
return waterLevel; return waterLevel;
} }
@ -256,7 +270,5 @@ public class Map {
*/ */
public char getDataTileValue(int x,int y) { public char getDataTileValue(int x,int y) {
return (char)(data[y*Map.MAP_WIDTH+x]-32768); return (char)(data[y*Map.MAP_WIDTH+x]-32768);
} }
} }

@ -41,6 +41,10 @@ public enum Maps {
map.ModifyDataTile(tileX, tileY, selectedDataTile); map.ModifyDataTile(tileX, tileY, selectedDataTile);
} }
public void ModifyDataTileValue(int tileX, int tileY, char value) {
map.ModifyDataTile(tileX, tileY, value);
}
public Tile getTile(int x,int y) { public Tile getTile(int x,int y) {
int index = y*Map.MAP_WIDTH+x; int index = y*Map.MAP_WIDTH+x;
if (index<0||index>=this.map.tiles.length) { if (index<0||index>=this.map.tiles.length) {
@ -59,6 +63,15 @@ public enum Maps {
} }
} }
public char getDataTileValue(int x, int y) {
int index = y*Map.MAP_WIDTH+x;
if (index<0||index>=this.map.data.length) {
return (char)DataTile.NULL.ordinal();
} else {
return this.map.data[index];
}
}
public View getView(int x,int y) { public View getView(int x,int y) {
int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X; int index = (y/Tile.TILE_SCREEN_COUNT_Y)*(Map.MAP_WIDTH/Tile.TILE_WIDTH)+x/Tile.TILE_SCREEN_COUNT_X;
if (index<0||index>=this.map.views.length) { if (index<0||index>=this.map.views.length) {

@ -98,6 +98,7 @@ public class ConfigureControls extends Object{
port = stream.readByte(); port = stream.readByte();
} while (port!=(byte)-2); } while (port!=(byte)-2);
} }
FillInDefaults();
updateHighlightSections(); updateHighlightSections();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -105,6 +106,16 @@ public class ConfigureControls extends Object{
} }
} }
private static void FillInDefaults() {
for (Action a : Action.values()) {
if (KeyBind.KEYBINDS.get(a)==null||KeyBind.KEYBINDS.get(a).size()==0) {
List<KeyBind> keybinds = KeyBind.KEYBINDS.getOrDefault(a,new ArrayList<>());
keybinds.addAll(RabiClone.DEFAULT_KEYBINDS.get(a));
KeyBind.KEYBINDS.put(a,keybinds);
}
}
}
private static void appendToKeybind(Action a,KeyBind kb) { private static void appendToKeybind(Action a,KeyBind kb) {
List<KeyBind> binds = KeyBind.KEYBINDS.getOrDefault(a,new ArrayList<KeyBind>()); List<KeyBind> binds = KeyBind.KEYBINDS.getOrDefault(a,new ArrayList<KeyBind>());
binds.add(kb); binds.add(kb);
@ -269,7 +280,7 @@ public class ConfigureControls extends Object{
@Override @Override
@SuppressWarnings("incomplete") @SuppressWarnings("incomplete-switch")
public void KeyPressed(Action a) { public void KeyPressed(Action a) {
switch(a) { switch(a) {
case PLAY_GAME:{ case PLAY_GAME:{
@ -287,8 +298,6 @@ public class ConfigureControls extends Object{
Map.LoadMap(RabiClone.CURRENT_MAP); Map.LoadMap(RabiClone.CURRENT_MAP);
RabiClone.OBJ.add(RabiClone.level_renderer = new EditorRenderer(RabiClone.p)); RabiClone.OBJ.add(RabiClone.level_renderer = new EditorRenderer(RabiClone.p));
}break; }break;
default:
break;
} }
} }

@ -33,7 +33,8 @@ public class EditorRenderer extends LevelRenderer{
boolean dataTileView=false; boolean dataTileView=false;
boolean inputDataTileValue=false; boolean inputDataTileValue=false;
char dataTileValue=0; String dataTileValue=new String("");
int storedTileX,storedTileY;
String inputMessageLogDisplay = new String(); String inputMessageLogDisplay = new String();
@ -72,9 +73,13 @@ public class EditorRenderer extends LevelRenderer{
int tileX = (int)(RabiClone.MOUSE_POS.getX()+getX())/Tile.TILE_WIDTH; int tileX = (int)(RabiClone.MOUSE_POS.getX()+getX())/Tile.TILE_WIDTH;
int tileY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT; int tileY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT;
if (dataTileView) { if (dataTileView) {
RabiClone.CURRENT_MAP.ModifyDataTile(tileX, tileY, selectedDataTile);
if (selectedDataTile==DataTile.DATATILE) { if (selectedDataTile==DataTile.DATATILE) {
inputDataTileValue=true; inputDataTileValue=true;
inputMessageLogDisplay=new String("Enter a Data Value: ");
storedTileX=tileX;
storedTileX=tileY;
} else {
RabiClone.CURRENT_MAP.ModifyDataTile(tileX, tileY, selectedDataTile);
} }
} else { } else {
RabiClone.CURRENT_MAP.ModifyTile(tileX, tileY, selectedTile); RabiClone.CURRENT_MAP.ModifyTile(tileX, tileY, selectedTile);
@ -141,7 +146,9 @@ public class EditorRenderer extends LevelRenderer{
} }
if (dataTileView) { if (dataTileView) {
drawMapTileForDataTileMode(p,x,y); drawMapTileForDataTileMode(p,x,y);
if (RabiClone.CURRENT_MAP.getDataTile(x, y)!=DataTile.NULL) { if (RabiClone.CURRENT_MAP.getDataTileValue(x, y)>=32768) {
DrawDataTileValue(p,x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getDataTileValue(x, y));
} else if (RabiClone.CURRENT_MAP.getDataTile(x, y)!=DataTile.NULL) {
DrawDataTile(p,x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getDataTile(x, y)); DrawDataTile(p,x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getDataTile(x, y));
} }
} else { } else {
@ -162,6 +169,10 @@ public class EditorRenderer extends LevelRenderer{
} }
Draw_Rect(p,PaletteColor.YELLOW,2,0,messageLog.getBounds(Font.PROFONT_12).getX(),messageLog.getBounds(Font.PROFONT_12).getY()); Draw_Rect(p,PaletteColor.YELLOW,2,0,messageLog.getBounds(Font.PROFONT_12).getX(),messageLog.getBounds(Font.PROFONT_12).getY());
Draw_Text(4,0,messageLog,Font.PROFONT_12); Draw_Text(4,0,messageLog,Font.PROFONT_12);
Draw_Rect(p,PaletteColor.YELLOW,2,messageLog.getBounds(Font.PROFONT_12).getY()+10,inputMessageLogDisplay.getBounds(Font.PROFONT_12).getX(),inputMessageLogDisplay.getBounds(Font.PROFONT_12).getY());
Draw_Text(4,messageLog.getBounds(Font.PROFONT_12).getY()+12,inputMessageLogDisplay,Font.PROFONT_12);
Draw_Rect(p,PaletteColor.YELLOW,4+inputMessageLogDisplay.getBounds(Font.PROFONT_12).getX()+2,messageLog.getBounds(Font.PROFONT_12).getY()+10,dataTileValue.getBounds(Font.PROFONT_12).getX(),dataTileValue.getBounds(Font.PROFONT_12).getY());
Draw_Text_Ext(4+inputMessageLogDisplay.getBounds(Font.PROFONT_12).getX()+4,messageLog.getBounds(Font.PROFONT_12).getY()+12,dataTileValue,Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.DEEP_RUBY);
Draw_Text(4,RabiClone.BASE_HEIGHT-Font.PROFONT_12.getGlyphHeight()-4,HELP_TEXT,Font.PROFONT_12); Draw_Text(4,RabiClone.BASE_HEIGHT-Font.PROFONT_12.getGlyphHeight()-4,HELP_TEXT,Font.PROFONT_12);
} }
@ -227,10 +238,19 @@ public class EditorRenderer extends LevelRenderer{
Draw_Text_Ext(x+2,y+2,new String(tile.toString()),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.WHITE); Draw_Text_Ext(x+2,y+2,new String(tile.toString()),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.WHITE);
} }
protected void DrawTransparentDataTile(byte[] p, double x, double y, char tile,PaletteColor col) {
Draw_Rect(p,col,x,y,Tile.TILE_WIDTH,Tile.TILE_HEIGHT);
Draw_Text_Ext(x+2,y+2,new String("V:").append(Integer.toString(tile-32768)),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.WHITE);
}
protected void DrawDataTile(byte[] p, double x, double y, DataTile tile) { protected void DrawDataTile(byte[] p, double x, double y, DataTile tile) {
DrawTransparentDataTile(p,x,y,tile,PaletteColor.MIDNIGHT_BLUE); DrawTransparentDataTile(p,x,y,tile,PaletteColor.MIDNIGHT_BLUE);
} }
private void DrawDataTileValue(byte[] p, double x, double y, char tile) {
DrawTransparentDataTile(p,x,y,tile,PaletteColor.RAZZMIC_BERRY);
}
@Override @Override
@SuppressWarnings("incomplete-switch") @SuppressWarnings("incomplete-switch")
public void KeyPressed(Action a) { public void KeyPressed(Action a) {
@ -255,6 +275,28 @@ public class EditorRenderer extends LevelRenderer{
case EDITOR_SET_BACKGROUND:{ case EDITOR_SET_BACKGROUND:{
RabiClone.CURRENT_MAP.setBackground(tileX,tileY,Background.values()[(RabiClone.CURRENT_MAP.getBackground(tileX, tileY).ordinal()+1)%Background.values().length]); RabiClone.CURRENT_MAP.setBackground(tileX,tileY,Background.values()[(RabiClone.CURRENT_MAP.getBackground(tileX, tileY).ordinal()+1)%Background.values().length]);
}break; }break;
case _0:
case _1:
case _2:
case _3:
case _4:
case _5:
case _6:
case _7:
case _8:
case _9:
dataTileValue=dataTileValue.append(a.toString().replace("_",""));
break;
case BACKSPACE:{
if (dataTileValue.length()>0) {
dataTileValue=dataTileValue.substring(0, dataTileValue.length()-1);
}
}break;
case ENTER:{
inputDataTileValue=false;
RabiClone.CURRENT_MAP.ModifyDataTileValue(tileX, tileY, (char)Integer.parseInt(dataTileValue.toString()));
dataTileValue.clear();
}break;
} }
} }

@ -45,7 +45,7 @@ public class LevelRenderer extends Object{
if (x<0||x>Map.MAP_WIDTH) { if (x<0||x>Map.MAP_WIDTH) {
continue; continue;
} }
if (RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL) { if (RabiClone.CURRENT_MAP.getDataTileValue(x,y)<32768&&RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL) {
if (!RabiClone.CURRENT_MAP.getDataTile(x,y).perform(x*Tile.TILE_WIDTH,y*Tile.TILE_HEIGHT)) { if (!RabiClone.CURRENT_MAP.getDataTile(x,y).perform(x*Tile.TILE_WIDTH,y*Tile.TILE_HEIGHT)) {
RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL); RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL);
} }

Loading…
Cancel
Save