From 65d7ed8cce4bf6fc477d674c75d7c9430bcc5703 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 22 Jun 2022 22:52:17 -0500 Subject: [PATCH] Add right click editor removal Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- bin/controls.config | Bin 483 -> 554 bytes src/sig/engine/KeyBind.java | 2 +- src/sig/events/DataEvent.java | 10 +++++ src/sig/events/Event.java | 3 -- src/sig/events/SpawnEvent.java | 10 +---- src/sig/events/WaterEvent.java | 13 ++++++ src/sig/map/DataTile.java | 18 +++++---- src/sig/map/Map.java | 21 ++++++++++ src/sig/objects/EditorRenderer.java | 59 ++++++++++++++++++---------- 9 files changed, 96 insertions(+), 40 deletions(-) create mode 100644 src/sig/events/DataEvent.java create mode 100644 src/sig/events/WaterEvent.java diff --git a/bin/controls.config b/bin/controls.config index eb3def4285662fec504607b0412380b9c8fe8f73..4914864d2197de3d8d2929cac51e4c32aecd66b1 100644 GIT binary patch delta 21 dcmaFNyozPQ)rkrY>=g_Qd)6_=Y`n_H2mo7!2gU#Z delta 11 ScmZ3*@|bzT)y*=De2f4bkptNP diff --git a/src/sig/engine/KeyBind.java b/src/sig/engine/KeyBind.java index c15933f..79a9f1b 100644 --- a/src/sig/engine/KeyBind.java +++ b/src/sig/engine/KeyBind.java @@ -62,7 +62,7 @@ public class KeyBind { } } else if (RabiClone.CONTROLLERS.length>port && id instanceof Identifier.Axis) { - return Math.abs(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())>=RabiClone.CONTROLLERS[port].getComponent(id).getDeadZone()&&Math.signum(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())==Math.signum(val); + return Math.abs(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())>=Math.max(RabiClone.CONTROLLERS[port].getComponent(id).getDeadZone(),0.2)&&Math.signum(RabiClone.CONTROLLERS[port].getComponent(id).getPollData())==Math.signum(val); } else { return false; diff --git a/src/sig/events/DataEvent.java b/src/sig/events/DataEvent.java new file mode 100644 index 0000000..963a92e --- /dev/null +++ b/src/sig/events/DataEvent.java @@ -0,0 +1,10 @@ +package sig.events; + +public class DataEvent implements Event{ + + @Override + public boolean perform(int x, int y) { + return true; + } + +} diff --git a/src/sig/events/Event.java b/src/sig/events/Event.java index a28402c..96e279e 100644 --- a/src/sig/events/Event.java +++ b/src/sig/events/Event.java @@ -1,9 +1,6 @@ package sig.events; -import sig.engine.String; - public interface Event{ - public String getDescription(); /** * Perform this event at position {@code (x,y)}. * @return {@code True} to keep this event alive after it runs. diff --git a/src/sig/events/SpawnEvent.java b/src/sig/events/SpawnEvent.java index b4a894f..a097387 100644 --- a/src/sig/events/SpawnEvent.java +++ b/src/sig/events/SpawnEvent.java @@ -3,23 +3,15 @@ package sig.events; import java.lang.reflect.InvocationTargetException; import sig.RabiClone; -import sig.engine.String; import sig.engine.objects.Object; import sig.map.Tile; public class SpawnEvent implements Event{ Class entity; - String description; - public SpawnEvent(java.lang.String description,Class o) { + public SpawnEvent(Class o) { this.entity=o; - this.description=new String(description); - } - - @Override - public String getDescription() { - return description; } @Override diff --git a/src/sig/events/WaterEvent.java b/src/sig/events/WaterEvent.java new file mode 100644 index 0000000..0284b07 --- /dev/null +++ b/src/sig/events/WaterEvent.java @@ -0,0 +1,13 @@ +package sig.events; + +import sig.RabiClone; + +public class WaterEvent implements Event{ + + @Override + public boolean perform(int x, int y) { + RabiClone.CURRENT_MAP.getMap().setWaterLevel(RabiClone.CURRENT_MAP.getMap().getDataTileValue(x+1, y)); + return true; + } + +} diff --git a/src/sig/map/DataTile.java b/src/sig/map/DataTile.java index 90f0205..e8848a1 100644 --- a/src/sig/map/DataTile.java +++ b/src/sig/map/DataTile.java @@ -1,8 +1,10 @@ package sig.map; import sig.engine.String; +import sig.events.DataEvent; import sig.events.Event; import sig.events.SpawnEvent; +import sig.events.WaterEvent; import sig.objects.enemies.BlueBun; import sig.objects.Erinoah; import sig.objects.enemies.GreenBun; @@ -11,11 +13,13 @@ import sig.objects.enemies.YellowBun; public enum DataTile { NULL, //File is populated by 0s by default. This represents nothing. - BUN0(new SpawnEvent("Spawns an Erinoa bun",Erinoah.class)), - BUN1(new SpawnEvent("Spawns a red bun",RedBun.class)), - BUN2(new SpawnEvent("Spawns a blue bun",BlueBun.class)), - BUN3(new SpawnEvent("Spawns a yellow bun",YellowBun.class)), - BUN4(new SpawnEvent("Spawns a green bun",GreenBun.class)); + BUN0("Spawns an Erinoa bun",new SpawnEvent(Erinoah.class)), + BUN1("Spawns a red bun",new SpawnEvent(RedBun.class)), + BUN2("Spawns a blue bun",new SpawnEvent(BlueBun.class)), + BUN3("Spawns a yellow bun",new SpawnEvent(YellowBun.class)), + BUN4("Spawns a green bun",new SpawnEvent(GreenBun.class)), + WATERLEVEL("Sets the water level according to the data tile at X+1",new WaterEvent()), + DATATILE("Uses a value between 32768-65536 to represent extra data.",new DataEvent()); String description; Event event; @@ -23,8 +27,8 @@ public enum DataTile { DataTile(){ this.description=new String(""); } - DataTile(Event e) { - this.description=e.getDescription(); + DataTile(java.lang.String description,Event e) { + this.description=new String(description); this.event=e; } public String getDescription() { diff --git a/src/sig/map/Map.java b/src/sig/map/Map.java index c51e12c..f03d51e 100644 --- a/src/sig/map/Map.java +++ b/src/sig/map/Map.java @@ -37,6 +37,8 @@ public class Map { byte[] types = new byte[MAP_SCREENS_X*MAP_SCREENS_Y]; char[] data = new char[MAP_WIDTH*MAP_HEIGHT]; + char waterLevel = 144; + int eventTileCount=0; final static byte MAP_DATA = 0; @@ -238,4 +240,23 @@ public class Map { 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 char getWaterLevel() { + return waterLevel; + } + + public void setWaterLevel(char waterLevel) { + this.waterLevel = waterLevel; + } + + /* + * This will return the tile's value minus 32768. + * This value represents a data tile value, but not + * necessarily a data tile. + */ + public char getDataTileValue(int x,int y) { + return (char)(data[y*Map.MAP_WIDTH+x]-32768); + } + + } diff --git a/src/sig/objects/EditorRenderer.java b/src/sig/objects/EditorRenderer.java index 21ae7da..b7c30c1 100644 --- a/src/sig/objects/EditorRenderer.java +++ b/src/sig/objects/EditorRenderer.java @@ -32,6 +32,10 @@ public class EditorRenderer extends LevelRenderer{ final static char CAMERA_SPD = 512; boolean dataTileView=false; + boolean inputDataTileValue=false; + char dataTileValue=0; + + String inputMessageLogDisplay = new String(); public EditorRenderer(Panel panel) { super(panel); @@ -58,27 +62,42 @@ public class EditorRenderer extends LevelRenderer{ if (up-down!=0) { setY(Math.max(0,getY()+(down-up)*CAMERA_SPD*updateMult)); } - boolean left_mb = MouseHeld(MouseEvent.BUTTON1); - // boolean middle_mb = MouseHeld(MouseEvent.BUTTON2); - // boolean right_mb = MouseHeld(MouseEvent.BUTTON3); - - if(left_mb){ - 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); - } else { - RabiClone.CURRENT_MAP.ModifyTile(tileX, tileY, selectedTile); + + if (!inputDataTileValue) { + boolean left_mb = MouseHeld(MouseEvent.BUTTON1); + // boolean middle_mb = MouseHeld(MouseEvent.BUTTON2); + boolean right_mb = MouseHeld(MouseEvent.BUTTON3); + + if(left_mb){ + 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; + } + } else { + RabiClone.CURRENT_MAP.ModifyTile(tileX, tileY, selectedTile); + } } - } - if(KeyHeld(Action.SLIDE)&&KeyHeld(Action.FALL)){ - AddMessage("Saving map..."); - try { - Map.SaveMap(RabiClone.CURRENT_MAP); - AddMessage(RabiClone.CURRENT_MAP.toString()," has been saved successfully."); - } catch (IOException e) { - e.printStackTrace(); - AddMessage(PaletteColor.RED,"Map failed to save: ",e.getLocalizedMessage()); + if (right_mb) { + 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, DataTile.NULL); + } else { + RabiClone.CURRENT_MAP.ModifyTile(tileX, tileY, Tile.VOID); + } + } + if(KeyHeld(Action.SLIDE)&&KeyHeld(Action.FALL)){ + AddMessage("Saving map..."); + try { + Map.SaveMap(RabiClone.CURRENT_MAP); + AddMessage(RabiClone.CURRENT_MAP.toString()," has been saved successfully."); + } catch (IOException e) { + e.printStackTrace(); + AddMessage(PaletteColor.RED,"Map failed to save: ",e.getLocalizedMessage()); + } } } updateMessageLog();