From b1919b54d460bee8845c9969ac9eb36b6c5c9742 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 23 Jun 2022 00:00:16 -0500 Subject: [PATCH] Begin implementation of data tiles with extra value storage Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- README.md | 2 +- bin/controls.config | Bin 554 -> 547 bytes maps/world1.map | Bin 299080 -> 299084 bytes src/sig/engine/Action.java | 14 +++++++- src/sig/engine/String.java | 46 ++++++++++++++++++++++++ src/sig/map/Map.java | 30 +++++++++++----- src/sig/map/Maps.java | 13 +++++++ src/sig/objects/ConfigureControls.java | 15 ++++++-- src/sig/objects/EditorRenderer.java | 48 +++++++++++++++++++++++-- src/sig/objects/LevelRenderer.java | 2 +- 10 files changed, 152 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 09eccf7..e12b646 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/controls.config b/bin/controls.config index 4914864d2197de3d8d2929cac51e4c32aecd66b1..84df5e8b293f8577a4637b9332e15e69d4a37105 100644 GIT binary patch delta 230 zcmXBKI}QPH9K`Y2WD8L^frKOM`%xlWNkot+Ep|QP5U#)(bXxcOvtPevGWpEB{g?k3 zKX0SY&>MJn?G#F1Ng=U!9Yh8ZZ~$V17&ronK>{>DYLEggkQrpa3CIm{;0zSNRw|GS jQre{iu0UWA0JYOp6U{W&TFZZ{Z0Yd%B1gpcH}m4 literal 554 zcmb`FT}s1H5QRUN;12qtbr%xbG)8ZmV57xS$U|FD5Un++kFLlSxVF(VHwN*cPs)YK z{GKy&2xAJaNU6CXC*za~K7qcQAxyaCo`$vTiU)d3c~P!m$&I3tZOjg2z0adNy|p~p zD0+rtxyBDy5aXz0I&h}sznIt^1}pjfw|po~n{-rjYuv{%E2L!njs7(|6oWZtPcgE#y>_ kwXkw|vvz*FtE&=X*N@$}KGQyhj-U7+;MXFEiB9v7=@;@Okgn;?%(^b delta 40 wcmX@JKFEiB9v7zL-ZOkgqP=iuUH;Njw95a8lx5aAL40QKAmbpQYW diff --git a/src/sig/engine/Action.java b/src/sig/engine/Action.java index a52dc7f..81cfeaf 100644 --- a/src/sig/engine/Action.java +++ b/src/sig/engine/Action.java @@ -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; diff --git a/src/sig/engine/String.java b/src/sig/engine/String.java index 7af2927..2b4743a 100644 --- a/src/sig/engine/String.java +++ b/src/sig/engine/String.java @@ -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(); } diff --git a/src/sig/map/Map.java b/src/sig/map/Map.java index f03d51e..c3de57d 100644 --- a/src/sig/map/Map.java +++ b/src/sig/map/Map.java @@ -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; } @@ -256,7 +270,5 @@ public class Map { */ public char getDataTileValue(int x,int y) { return (char)(data[y*Map.MAP_WIDTH+x]-32768); - } - - + } } diff --git a/src/sig/map/Maps.java b/src/sig/map/Maps.java index ba0ff6b..994e056 100644 --- a/src/sig/map/Maps.java +++ b/src/sig/map/Maps.java @@ -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) { diff --git a/src/sig/objects/ConfigureControls.java b/src/sig/objects/ConfigureControls.java index bfed807..687a0c5 100644 --- a/src/sig/objects/ConfigureControls.java +++ b/src/sig/objects/ConfigureControls.java @@ -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 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 binds = KeyBind.KEYBINDS.getOrDefault(a,new ArrayList()); 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; } } diff --git a/src/sig/objects/EditorRenderer.java b/src/sig/objects/EditorRenderer.java index b7c30c1..f62206c 100644 --- a/src/sig/objects/EditorRenderer.java +++ b/src/sig/objects/EditorRenderer.java @@ -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; } } diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index 457596d..c58df09 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -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); }