Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from TheCahyag/fix/incorrectly-rendering-large-…
Browse files Browse the repository at this point in the history
…contents

Fixed serializing and deserializing SubSpaces
  • Loading branch information
TheCahyag authored Dec 20, 2017
2 parents ba26e82 + 9e9a0f1 commit 9d471f8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public CommandResult execute(CommandSource src, @Nullable CommandContext args) t
SECONDARY_COLOR, animation.getTickDelay() + "\n",
PRIMARY_COLOR, "Start Frame",
WHITE, ": ",
SECONDARY_COLOR, this.animation.getFrameIndex() + "\n",
SECONDARY_COLOR, this.animation.getStartFrameIndex() + "\n",
PRIMARY_COLOR, "Cycles to Complete",
WHITE, ": ",
SECONDARY_COLOR, this.animation.getCycles() + "\n"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;

/**
* File: FrameElement.java
Expand Down Expand Up @@ -40,4 +41,8 @@ protected Object parseValue(CommandSource source, CommandArgs args) throws Argum
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
return null;
}

public Optional<Frame> getFrame() {
return Optional.ofNullable(this.frame);
}
}
31 changes: 19 additions & 12 deletions src/main/java/com/servegame/bl4de/Animation/model/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Animation implements DataSerializable{
private String animationName;
private List<Frame> frames;
private SubSpace3D masterSubSpace;
private int frameIndex = 0;
private int startFrameIndex = 0;
private int tickDelay = 20;
private int cycles = -1;

Expand Down Expand Up @@ -202,7 +202,7 @@ public boolean isRunning(){
* @param frame the starting {@link Frame}
*/
public void start(int frame) throws UninitializedException {
this.frameIndex = frame;
this.startFrameIndex = frame;
setStatus(Status.RUNNING);
if (AnimationController.saveAnimation(this)){
AnimationPlugin.taskManager.createBatch(this);
Expand Down Expand Up @@ -240,7 +240,7 @@ public void stop(){
* Pauses the {@link Animation}.
*
* There's no need to specifically save {@link Frame} it was on because
* that is always saved under the {@link Animation#frameIndex} state.
* that is always saved under the {@link Animation#startFrameIndex} state.
*/
public void pause(){
setStatus(Status.PAUSED);
Expand Down Expand Up @@ -383,16 +383,16 @@ public void deleteFrame(Frame frame){
* Getter for the frame index (-f flag in {@link StartAnimation} command)
* @return int - the frame the animation will start on when it is ran
*/
public int getFrameIndex() {
return frameIndex;
public int getStartFrameIndex() {
return startFrameIndex;
}

/**
* Setter for the frame index (-f flag in {@link StartAnimation} command)
* @param frameIndex int - the new frame index
* @param startFrameIndex int - the new frame index
*/
public void setFrameIndex(int frameIndex) {
this.frameIndex = frameIndex;
public void setStartFrameIndex(int startFrameIndex) {
this.startFrameIndex = startFrameIndex;
}

/**
Expand Down Expand Up @@ -441,7 +441,7 @@ public String toString() {
", \nanimationName='" + animationName + '\'' +
", \nframes=" + frames +
", \nmasterSubSpace=\n" + masterSubSpace +
", \nframeIndex=" + frameIndex +
", \nstartFrameIndex=" + startFrameIndex +
", \ntickDelay=" + tickDelay +
", \ncycles=" + cycles +
"\n}";
Expand All @@ -466,7 +466,7 @@ public DataContainer toContainer() {
.set(ANIMATION_NAME, getAnimationName()) // String
.set(ANIMATION_FRAMES, getFrames()) // List<Frame>
.set(ANIMATION_SUBSPACE, getSubSpace()) // SubSpace3D
.set(ANIMATION_FRAME_INDEX, getFrameIndex()) // int
.set(ANIMATION_FRAME_INDEX, getStartFrameIndex()) // int
.set(ANIMATION_TICK_DELAY, getTickDelay()) // int
.set(ANIMATION_CYCLES, getCycles()); // int

Expand Down Expand Up @@ -520,7 +520,7 @@ protected Optional<Animation> buildContent(DataView container) throws InvalidDat
// Create animation and set information
animation = new Animation(owner, name);
animation.setStatus(status);
animation.setFrameIndex(frameIndex);
animation.setStartFrameIndex(frameIndex);
animation.setTickDelay(tickDelay);
animation.setCycles(cycles);

Expand Down Expand Up @@ -626,7 +626,14 @@ public static Animation deserialize(String item) {
return null;
}

public static DataContainer hoconToContainer(String hoconString) throws InvalidDataException, IOException {
/**
* Creates a {@link DataContainer} from a {@link DataFormats#HOCON} String
* @param hoconString HOCON string to convert to a DataContainer
* @return {@link DataContainer} that is an object representation of the provided
* HOCON string
* @throws IOException
*/
public static DataContainer hoconToContainer(String hoconString) throws IOException {
HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
.setHeaderMode(HeaderMode.PRESET)
.setSource(() -> new BufferedReader(new StringReader(hoconString)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public DataContainer toContainer() {
for (int j = 0; j < y; j++) {
// Z
for (int k = 0; k < z; k++) {
container.set(DataQuery.of("" + i + j + k), blockSnapshots[i][j][k].toContainer());
container.set(DataQuery.of(i + "|" + j + "|" + k), blockSnapshots[i][j][k].toContainer());
}
}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ protected Optional<SubSpace3D> buildContent(DataView container) throws InvalidDa
for (int j = 0; j < y; j++) {
// Z
for (int k = 0; k < z; k++) {
blockSnapshots[i][j][k] = BlockSnapshot.builder().build(container.getView(DataQuery.of("" + i + j + k)).get()).get();
blockSnapshots[i][j][k] = BlockSnapshot.builder().build(container.getView(DataQuery.of(i + "|" + j + "|" + k)).get()).get();
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/servegame/bl4de/Animation/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,27 @@ public static void copySubSpaceToWorld(SubSpace3D subSpace) throws Uninitialized
Location<World> corner2 = subSpace.getCornerTwo().get();
BlockSnapshot[][][] subSpaceSnapShot = subSpace.getContents().get();

// Get absolute length of sub space dimensions
int xLen = Math.abs(Math.abs(corner1.getBlockX()) - Math.abs(corner2.getBlockX()));
int yLen = Math.abs(Math.abs(corner1.getBlockY()) - Math.abs(corner2.getBlockY()));
int zLen = Math.abs(Math.abs(corner1.getBlockZ()) - Math.abs(corner2.getBlockZ()));

/* Get corner to start the copy at by getting the coordinates of the
numerically lowest coordinates of the two corners
(may result in a corner different from the parameters)*/
int xLow = corner1.getBlockX() <= corner2.getBlockX() ? corner1.getBlockX() : corner2.getBlockX();
int yLow = corner1.getBlockY() <= corner2.getBlockY() ? corner1.getBlockY() : corner2.getBlockY();
int zLow = corner1.getBlockZ() <= corner2.getBlockZ() ? corner1.getBlockZ() : corner2.getBlockZ();

int xLength = subSpaceSnapShot.length;
int yLength = subSpaceSnapShot[0].length;
int zLength = subSpaceSnapShot[0][0].length;
System.out.println(xLength + ", " + yLength + ", " + zLength);

// Y
for (int y = 0; y <= yLen; y++) {
for (int x = 0; x < xLength; x++) {
// Z
for (int z = 0; z <= zLen; z++) {
for (int y = 0; y < yLength; y++) {
// X
for (int x = 0; x <= xLen; x++) {
for (int z = 0; z < zLength; z++) {
BlockSnapshot snapshot = subSpaceSnapShot[x][y][z];
new Location<>(corner1.getExtent(), x + xLow, y + yLow, z + zLow)
.setBlock(snapshot.getState(), Cause.source(AnimationPlugin.plugin).build());
Location loc = new Location<>(corner1.getExtent(), x + xLow, y + yLow, z + zLow);
loc.setBlock(snapshot.getState(), Cause.source(AnimationPlugin.plugin).build());
}
}
}
Expand Down

0 comments on commit 9d471f8

Please sign in to comment.