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>
This commit is contained in:
parent
65d7ed8cce
commit
b1919b54d4
@ -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
|
||||
`finally` to suppress warnings relative to finally block that don’t return
|
||||
`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
|
||||
`null` to suppress warnings relative to null analysis
|
||||
`restriction` to suppress warnings relative to usage of discouraged or forbidden references
|
||||
|
Binary file not shown.
BIN
maps/world1.map
BIN
maps/world1.map
Binary file not shown.
@ -17,7 +17,19 @@ public enum Action {
|
||||
PLAY_GAME(new KeyBind(KeyEvent.VK_F1)),
|
||||
EDITOR_SET_VIEW(new KeyBind(KeyEvent.VK_F3)),
|
||||
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;
|
||||
Key controllingKey;
|
||||
|
@ -114,6 +114,52 @@ public class String{
|
||||
updateBounds(this.sb.toString());
|
||||
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() {
|
||||
return this.sb.length();
|
||||
}
|
||||
|
@ -230,17 +230,31 @@ public class Map {
|
||||
}
|
||||
|
||||
public void ModifyDataTile(int x,int y,DataTile t) {
|
||||
DataTile prevTile = DataTile.values()[data[y*Map.MAP_WIDTH+x]];
|
||||
if (prevTile.ordinal()==0) {
|
||||
eventTileCount++;
|
||||
}
|
||||
if (t.ordinal()==0) {
|
||||
if (data[y*Map.MAP_WIDTH+x]<32768) {
|
||||
DataTile prevTile = DataTile.values()[data[y*Map.MAP_WIDTH+x]];
|
||||
if (prevTile.ordinal()==0) {
|
||||
eventTileCount++;
|
||||
}
|
||||
if (t.ordinal()==0) {
|
||||
eventTileCount--;
|
||||
}
|
||||
data[y*Map.MAP_WIDTH+x]=(char)(t.ordinal());
|
||||
} else {
|
||||
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]+".");
|
||||
}
|
||||
|
||||
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() {
|
||||
return waterLevel;
|
||||
}
|
||||
@ -257,6 +271,4 @@ public class Map {
|
||||
public char getDataTileValue(int x,int y) {
|
||||
return (char)(data[y*Map.MAP_WIDTH+x]-32768);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -41,6 +41,10 @@ public enum Maps {
|
||||
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) {
|
||||
int index = y*Map.MAP_WIDTH+x;
|
||||
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) {
|
||||
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) {
|
||||
|
@ -98,6 +98,7 @@ public class ConfigureControls extends Object{
|
||||
port = stream.readByte();
|
||||
} while (port!=(byte)-2);
|
||||
}
|
||||
FillInDefaults();
|
||||
updateHighlightSections();
|
||||
} catch (IOException e) {
|
||||
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) {
|
||||
List<KeyBind> binds = KeyBind.KEYBINDS.getOrDefault(a,new ArrayList<KeyBind>());
|
||||
binds.add(kb);
|
||||
@ -269,7 +280,7 @@ public class ConfigureControls extends Object{
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("incomplete")
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public void KeyPressed(Action a) {
|
||||
switch(a) {
|
||||
case PLAY_GAME:{
|
||||
@ -287,8 +298,6 @@ public class ConfigureControls extends Object{
|
||||
Map.LoadMap(RabiClone.CURRENT_MAP);
|
||||
RabiClone.OBJ.add(RabiClone.level_renderer = new EditorRenderer(RabiClone.p));
|
||||
}break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,8 @@ public class EditorRenderer extends LevelRenderer{
|
||||
|
||||
boolean dataTileView=false;
|
||||
boolean inputDataTileValue=false;
|
||||
char dataTileValue=0;
|
||||
String dataTileValue=new String("");
|
||||
int storedTileX,storedTileY;
|
||||
|
||||
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 tileY = (int)(RabiClone.MOUSE_POS.getY()+getY())/Tile.TILE_HEIGHT;
|
||||
if (dataTileView) {
|
||||
RabiClone.CURRENT_MAP.ModifyDataTile(tileX, tileY, selectedDataTile);
|
||||
if (selectedDataTile==DataTile.DATATILE) {
|
||||
inputDataTileValue=true;
|
||||
inputMessageLogDisplay=new String("Enter a Data Value: ");
|
||||
storedTileX=tileX;
|
||||
storedTileX=tileY;
|
||||
} else {
|
||||
RabiClone.CURRENT_MAP.ModifyDataTile(tileX, tileY, selectedDataTile);
|
||||
}
|
||||
} else {
|
||||
RabiClone.CURRENT_MAP.ModifyTile(tileX, tileY, selectedTile);
|
||||
@ -141,7 +146,9 @@ public class EditorRenderer extends LevelRenderer{
|
||||
}
|
||||
if (dataTileView) {
|
||||
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));
|
||||
}
|
||||
} 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_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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public void KeyPressed(Action a) {
|
||||
@ -255,6 +275,28 @@ public class EditorRenderer extends LevelRenderer{
|
||||
case EDITOR_SET_BACKGROUND:{
|
||||
RabiClone.CURRENT_MAP.setBackground(tileX,tileY,Background.values()[(RabiClone.CURRENT_MAP.getBackground(tileX, tileY).ordinal()+1)%Background.values().length]);
|
||||
}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) {
|
||||
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)) {
|
||||
RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user