Skip to content

Commit

Permalink
Can now copy and paste HitboxToggle and HitboxTrigger info from their…
Browse files Browse the repository at this point in the history
… editors

+ Generalised saving and loading of HitboxToggle and HitboxTrigger information
+ Object can no longer be drawn when in a build mode editor
  • Loading branch information
defaultsamson committed Sep 25, 2016
1 parent 557c26d commit acd9cc6
Show file tree
Hide file tree
Showing 15 changed files with 584 additions and 296 deletions.
15 changes: 10 additions & 5 deletions src/ca/afroman/client/ClientGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import ca.afroman.entity.api.Direction;
import ca.afroman.entity.api.Entity;
import ca.afroman.entity.api.Hitbox;
import ca.afroman.events.HitboxToggleReceiver;
import ca.afroman.events.HitboxToggle;
import ca.afroman.events.HitboxTrigger;
import ca.afroman.events.IEvent;
import ca.afroman.events.TriggerType;
Expand Down Expand Up @@ -762,15 +762,20 @@ public void parsePacket(BytePacket packet)
case SET_PLAYER_LOCATION:
{
ByteBuffer buf = ByteBuffer.wrap(packet.getContent());
Role role = Role.fromOrdinal(buf.get());

PlayerEntity player = getPlayer(Role.fromOrdinal(buf.get()));
PlayerEntity player = getPlayer(role);

if (player != null)
{
player.setDirection(Direction.fromOrdinal(buf.get()));
player.setLastDirection(Direction.fromOrdinal(buf.get()));
player.setPosition(new Vector2DDouble(buf.getInt(), buf.getInt()));
}
else
{
logger().log(ALogType.WARNING, "No player with role " + role);
}
}
break;
case CONFIRM_RECEIVED:
Expand Down Expand Up @@ -910,7 +915,7 @@ public void parsePacket(BytePacket packet)
int width = buf.getInt();
int height = buf.getInt();

HitboxToggleReceiver trig = new HitboxToggleReceiver(true, id, x, y, width, height, null, null);
HitboxToggle trig = new HitboxToggle(true, id, x, y, width, height, null, null);
trig.addToLevel(level);
}
else
Expand All @@ -934,9 +939,9 @@ public void parsePacket(BytePacket packet)

if (eHitbox != null)
{
if (eHitbox instanceof HitboxToggleReceiver)
if (eHitbox instanceof HitboxToggle)
{
HitboxToggleReceiver hitbox = (HitboxToggleReceiver) eHitbox;
HitboxToggle hitbox = (HitboxToggle) eHitbox;

boolean enabled = buf.get() == 1;
List<Integer> triggersIn = ByteUtil.extractIntList(buf, Byte.MIN_VALUE, Byte.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import ca.afroman.entity.api.Hitbox;
import ca.afroman.entity.api.IServerClient;
import ca.afroman.level.Level;
import ca.afroman.level.LevelObjectType;

public class HitboxToggleReceiver implements IEvent, IServerClient
public class HitboxToggle implements IEvent, IServerClient
{
private boolean isServerSide;

Expand All @@ -17,12 +18,12 @@ public class HitboxToggleReceiver implements IEvent, IServerClient
private List<Integer> outTriggers;
private Hitbox hitbox;

public HitboxToggleReceiver(boolean isServerSide, int id, double x, double y, double width, double height, List<Integer> inTriggers, List<Integer> outTriggers)
public HitboxToggle(boolean isServerSide, int id, double x, double y, double width, double height, List<Integer> inTriggers, List<Integer> outTriggers)
{
this(isServerSide, id, new Hitbox(id, x, y, width, height), inTriggers, outTriggers);
}

public HitboxToggleReceiver(boolean isServerSide, int id, Hitbox box, List<Integer> inTriggers, List<Integer> outTriggers)
public HitboxToggle(boolean isServerSide, int id, Hitbox box, List<Integer> inTriggers, List<Integer> outTriggers)
{
this.isServerSide = isServerSide;
level = null;
Expand Down Expand Up @@ -156,6 +157,44 @@ public void tick()

}

@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(LevelObjectType.HITBOX_TOGGLE.toString());
sb.append('(');
sb.append(isEnabled() ? "true" : "false");
sb.append(", ");
sb.append(getX());
sb.append(", ");
sb.append(getY());
sb.append(", ");
sb.append(getWidth());
sb.append(", ");
sb.append(getHeight());
sb.append(", {");

// Saves in triggers
for (int k = 0; k < getInTriggers().size(); k++)
{
sb.append(getInTriggers().get(k));
if (k != getInTriggers().size() - 1) sb.append(", ");
}

sb.append("}, {");

// Saves out triggers
for (int k = 0; k < getOutTriggers().size(); k++)
{
sb.append(getOutTriggers().get(k));
if (k != getOutTriggers().size() - 1) sb.append(", ");
}

sb.append("})");

return sb.toString();
}

@Override
public void trigger(Entity triggerer)
{
Expand Down
117 changes: 117 additions & 0 deletions src/ca/afroman/events/HitboxToggleWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package ca.afroman.events;

import java.util.ArrayList;
import java.util.List;

import ca.afroman.level.LevelObjectType;
import ca.afroman.util.ParamUtil;

public class HitboxToggleWrapper
{
/**
* Takes a saved version of a HitboxToggle's information and parses it.
*
* @param input must be formatted as it is saved. e.g. HITBOX_TOGGLE(false, 0.0, 85.0, 33.0, 4.0, {22}, {})
* @return
*/
public static HitboxToggleWrapper fromString(String input)
{
String[] split = input.split("\\(");
LevelObjectType objectType = LevelObjectType.valueOf(split[0]);

if (objectType == LevelObjectType.HITBOX_TOGGLE)
{
String[] split2 = split[1].split("\\)");
String rawParameters = split2.length > 0 ? split2[0] : "";
String[] parameters = ParamUtil.getParameters(rawParameters);

boolean isEnabled = Boolean.parseBoolean(parameters[0]);
double x = Double.parseDouble(parameters[1]);
double y = Double.parseDouble(parameters[2]);
double width = Double.parseDouble(parameters[3]);
double height = Double.parseDouble(parameters[4]);

String[] rSubParameters = ParamUtil.getRawSubParameters(rawParameters);

List<Integer> inTriggers = new ArrayList<Integer>();
String[] inTriggerP = ParamUtil.getParameters(rSubParameters[0]);
if (inTriggerP != null)
{
for (String e : inTriggerP)
{
inTriggers.add(Integer.parseInt(e));
}
}

List<Integer> outTriggers = new ArrayList<Integer>();
String[] outTriggerP = ParamUtil.getParameters(rSubParameters[1]);
if (outTriggerP != null)
{
for (String e : outTriggerP)
{
outTriggers.add(Integer.parseInt(e));
}
}

return new HitboxToggleWrapper(isEnabled, x, y, width, height, inTriggers, outTriggers);
}
else
{
return null;
}
}
private boolean isEnabled;
private double x;
private double y;
private double width;
private double height;
private List<Integer> inTriggers;

private List<Integer> outTriggers;

public HitboxToggleWrapper(boolean isEnabled, double x, double y, double width, double height, List<Integer> inTriggers, List<Integer> outTriggers)
{
this.isEnabled = isEnabled;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.inTriggers = inTriggers;
this.outTriggers = outTriggers;
}

public double getHeight()
{
return height;
}

public List<Integer> getInTriggers()
{
return inTriggers;
}

public List<Integer> getOutTriggers()
{
return outTriggers;
}

public double getWidth()
{
return width;
}

public double getX()
{
return x;
}

public double getY()
{
return y;
}

public boolean isEnabled()
{
return isEnabled;
}
}
46 changes: 46 additions & 0 deletions src/ca/afroman/events/HitboxTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ca.afroman.entity.api.IServerClient;
import ca.afroman.input.InputType;
import ca.afroman.level.Level;
import ca.afroman.level.LevelObjectType;
import ca.afroman.packet.PacketActivateTrigger;
import ca.afroman.resource.IDCounter;
import ca.afroman.server.ServerGame;
Expand Down Expand Up @@ -214,6 +215,51 @@ public void tick()
}
}

@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(LevelObjectType.HITBOX_TRIGGER.toString());
sb.append('(');
sb.append(getX());
sb.append(", ");
sb.append(getY());
sb.append(", ");
sb.append(getWidth());
sb.append(", ");
sb.append(getHeight());
sb.append(", {");

// Saves trigger types
for (int k = 0; k < getTriggerTypes().size(); k++)
{
sb.append(getTriggerTypes().get(k).toString());
if (k != getTriggerTypes().size() - 1) sb.append(", ");
}

sb.append("}, {");

// Saves in triggers
for (int k = 0; k < getInTriggers().size(); k++)
{
sb.append(getInTriggers().get(k));
if (k != getInTriggers().size() - 1) sb.append(", ");
}

sb.append("}, {");

// Saves out triggers
for (int k = 0; k < getOutTriggers().size(); k++)
{
sb.append(getOutTriggers().get(k));
if (k != getOutTriggers().size() - 1) sb.append(", ");
}

sb.append("})");

return sb.toString();
}

@Override
public void trigger(Entity triggerer)
{
Expand Down
Loading

0 comments on commit acd9cc6

Please sign in to comment.