Skip to content

Commit

Permalink
to json adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Dec 28, 2024
1 parent 0609bc6 commit 8bf0cfb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package de.oliver.fancyholograms.storage.json;

import de.oliver.fancyholograms.api.data.HologramData;
import de.oliver.fancyholograms.api.data.TextHologramData;
import de.oliver.fancyholograms.api.data.*;
import de.oliver.fancyholograms.storage.json.model.*;

public class JsonAdapter {

public static JsonDataUnion toJson(TextHologramData data) {
JsonHologramData hologramData = new JsonHologramData(
public static JsonHologramData hologramDataToJson(HologramData data) {
return new JsonHologramData(
data.getName(),
data.getType(),
new JsonLocation(
Expand All @@ -22,8 +21,10 @@ public static JsonDataUnion toJson(TextHologramData data) {
data.getVisibility(),
data.getLinkedNpcName()
);
}

JsonDisplayHologramData displayHologramData = new JsonDisplayHologramData(
public static JsonDisplayHologramData displayHologramDataToJson(DisplayHologramData data) {
return new JsonDisplayHologramData(
new JsonVec3f(
data.getScale().x(),
data.getScale().y(),
Expand All @@ -40,20 +41,70 @@ public static JsonDataUnion toJson(TextHologramData data) {
data.getBrightness().getSkyLight(),
data.getBillboard()
);
}

JsonTextHologramData textHologramData = new JsonTextHologramData(
public static JsonTextHologramData textHologramDataToJson(TextHologramData data) {
return new JsonTextHologramData(
data.getText(),
data.hasTextShadow(),
data.isSeeThrough(),
data.getTextAlignment(),
data.getTextUpdateInterval(),
data.getBackground().toString()
);
}

public static JsonBlockHologramData blockHologramDataToJson(BlockHologramData data) {
return new JsonBlockHologramData(
data.getBlock().name()
);
}

public static JsonItemHologramData itemHologramDataToJson(ItemHologramData data) {
return new JsonItemHologramData(
new String(data.getItemStack().serializeAsBytes())
);
}

public static JsonDataUnion toUnion(TextHologramData data) {
JsonHologramData hologramData = hologramDataToJson(data);
JsonDisplayHologramData displayHologramData = displayHologramDataToJson(data);
JsonTextHologramData textHologramData = textHologramDataToJson(data);

return new JsonDataUnion(
hologramData,
displayHologramData,
textHologramData,
null,
null
);
}

public static JsonDataUnion toUnion(ItemHologramData data) {
JsonHologramData hologramData = hologramDataToJson(data);
JsonDisplayHologramData displayHologramData = displayHologramDataToJson(data);
JsonItemHologramData itemHologramData = itemHologramDataToJson(data);

return new JsonDataUnion(
hologramData,
displayHologramData,
null,
itemHologramData,
null
);
}

public static JsonDataUnion toUnion(BlockHologramData data) {
JsonHologramData hologramData = hologramDataToJson(data);
JsonDisplayHologramData displayHologramData = displayHologramDataToJson(data);
JsonBlockHologramData blockHologramData = blockHologramDataToJson(data);

return new JsonDataUnion(
hologramData,
displayHologramData,
textHologramData
null,
null,
blockHologramData
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.oliver.fancyholograms.storage.json.model;

public record JsonBlockHologramData(
String block_material
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
public record JsonDataUnion(
JsonHologramData hologram_data,
JsonDisplayHologramData display_hologram_data,
JsonTextHologramData text_hologram_data

JsonTextHologramData text_hologram_data,
JsonItemHologramData item_hologram_data,
JsonBlockHologramData block_hologram_data
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.oliver.fancyholograms.storage.json.model;

public record JsonItemHologramData(
String item
) {
}

0 comments on commit 8bf0cfb

Please sign in to comment.