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

Commit

Permalink
Finish 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ajh123 committed Nov 15, 2022
1 parent e1dcfa4 commit 26af347
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.ddns.minersonline.HistorySurvival.api.ecs;

import net.ddns.minersonline.HistorySurvival.api.auth.GameProfile;

public class PlayerComponent extends Component{
public GameProfile profile;

public TransformComponent transformComponent;

public PlayerComponent() {
}

public PlayerComponent(GameProfile profile) {
this.profile = profile;
}

@Override
public void start() {
super.start();
this.transformComponent = gameObject.getComponent(TransformComponent.class);
}
}
4 changes: 2 additions & 2 deletions buildTools/build_json_defs_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def sha1sum(filename):
"client": {
"sha1": sha1sum(os.path.join(args.gameJarDir, args.gameJar)),
"size": os.stat(os.path.join(args.gameJarDir, args.gameJar)).st_size,
"url": "https://minersonline.ddns.net/files/history_survival/packages/" + args.ver + "/" + args.gameJar
"url": "https://minersonline.tk/files/history_survival/packages/" + args.ver + "/" + args.gameJar
}
},
"id": "hs-" + args.ver,
Expand Down Expand Up @@ -128,7 +128,7 @@ def build_lib(name: str, ver: str, file: str):
"path": "HistorySurvival/" + file,
"sha1": sha1sum(os.path.join(lib_dir, file)),
"size": os.stat(os.path.join(lib_dir, file)).st_size,
"url": "https://minersonline.ddns.net/files/libs/" + file
"url": "https://minersonline.tk/files/libs/" + file
}

if has_natives:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.ddns.minersonline.HistorySurvival.api.data.models.TexturedModel;
import net.ddns.minersonline.HistorySurvival.api.ecs.Component;
import net.ddns.minersonline.HistorySurvival.api.ecs.GameObject;
import net.ddns.minersonline.HistorySurvival.api.ecs.PlayerComponent;
import net.ddns.minersonline.HistorySurvival.api.ecs.TransformComponent;
import net.ddns.minersonline.HistorySurvival.engine.DisplayManager;
import net.ddns.minersonline.HistorySurvival.engine.GameObjectManager;
Expand Down Expand Up @@ -70,7 +71,6 @@ public final void addGameObject(GameObject go){
metaData.gameObjects.add(go);
go.start();
}
System.out.println("Added "+go.getId());
}

public final void putGameObject(int index, GameObject go){
Expand Down Expand Up @@ -275,6 +275,29 @@ public void load(String path){
DelayedTask task = () -> Game.queue.add(() -> {
SceneMetaData scene = gson.fromJson(file, SceneMetaData.class);

File playersPath = new File(Paths.get(path+"/players").toString());
if (playersPath.exists() && playersPath.isDirectory()) {
File playerFile = Objects.requireNonNull(playersPath.listFiles())[0];
if (playerFile.isFile() && playerFile.exists()) {
try {
String data = new String(Files.readAllBytes(playerFile.toPath()));
PlayerComponent player = gson.fromJson(data, PlayerComponent.class);
GameObject playerObject = GameObjectManager.getGameObjectByFirstComponent(PlayerComponent.class);

TransformComponent transformComponent = playerObject.getComponent(TransformComponent.class);
if (transformComponent != null) {
transformComponent.position.set(player.transformComponent.position);
transformComponent.rotation.set(player.transformComponent.rotation);
transformComponent.scale = player.transformComponent.scale;
}

} catch (IOException e) {
e.printStackTrace();
}
}
}


File objectsPath = new File(Paths.get(path+"/objects").toString());
if (objectsPath.exists() && objectsPath.isDirectory()) {
for (File objectFile : Objects.requireNonNull(objectsPath.listFiles())) {
Expand All @@ -293,7 +316,7 @@ public void load(String path){
}

for (GameObject go : scene.gameObjects) {
if (go.getComponent(ControllableComponent.class) == null) {
if (go.getComponent(PlayerComponent.class) == null) {
addGameObject(go);
go.start();
}
Expand All @@ -319,11 +342,20 @@ public void save(String path){
levelWriter.close();

for (GameObject object : this.metaData.gameObjects) {
if (object.getComponent(ControllableComponent.class) == null) {
if (object.getComponent(PlayerComponent.class) == null) {
Files.createDirectories(Paths.get(path+"/objects"));
FileWriter objectWriter = new FileWriter(path+"/objects/"+object.getId()+".json");
objectWriter.write(gson.toJson(object));
objectWriter.close();
objectWriter.close();
} else {
PlayerComponent player = object.getComponent(PlayerComponent.class);

if (player != null && player.profile != null) {
Files.createDirectories(Paths.get(path + "/players"));
FileWriter objectWriter = new FileWriter(path + "/players/" + player.profile.getRawId() + ".json");
objectWriter.write(gson.toJson(player));
objectWriter.close();
}
}
}
} catch (IOException e){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.ddns.minersonline.HistorySurvival.engine.entities;

import net.ddns.minersonline.HistorySurvival.api.auth.GameProfile;
import net.ddns.minersonline.HistorySurvival.api.ecs.Component;
import net.ddns.minersonline.HistorySurvival.api.ecs.TransformComponent;
import net.ddns.minersonline.HistorySurvival.api.voxel.VoxelChunk;
Expand All @@ -22,18 +21,16 @@ public class ControllableComponent extends Component {
public float currentTurnSpeed;
public float upwardsSpeed;
public boolean isJump;
public transient GameProfile profile;

private transient TransformComponent transformComponent;

public ControllableComponent() {}

public ControllableComponent(VoxelWorld world, float currentSpeed, float currentTurnSpeed, float upwardsSpeed, boolean isJump, GameProfile profile) {
public ControllableComponent(VoxelWorld world, float currentSpeed, float currentTurnSpeed, float upwardsSpeed, boolean isJump) {
this.currentSpeed = currentSpeed;
this.currentTurnSpeed = currentTurnSpeed;
this.upwardsSpeed = upwardsSpeed;
this.isJump = isJump;
this.profile = profile;
this.world = world;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import imgui.ImGui;
import imgui.type.ImBoolean;
import net.ddns.minersonline.HistorySurvival.Game;
import net.ddns.minersonline.HistorySurvival.GameSettings;
import net.ddns.minersonline.HistorySurvival.Scene;
import net.ddns.minersonline.HistorySurvival.api.GameHook;
import net.ddns.minersonline.HistorySurvival.api.auth.GameProfile;
import net.ddns.minersonline.HistorySurvival.api.ecs.PlayerComponent;
import net.ddns.minersonline.HistorySurvival.engine.GameObjectManager;
import net.ddns.minersonline.HistorySurvival.engine.entities.ControllableComponent;
import net.ddns.minersonline.HistorySurvival.api.ecs.GameObject;
Expand Down Expand Up @@ -80,6 +83,7 @@ public void init() {

if (!levelLoaded) {
player = new GameObject();
player.addComponent(new PlayerComponent(new GameProfile(GameSettings.uuid, GameSettings.username)));
player.addComponent(new ControllableComponent(metaData.world));
player.addComponent(new MeshComponent(ModelType.PLAYER_MODEL.create()));
player.addComponent(new TransformComponent(new Vector3f(worldCenter), new Vector3f(0, 0, 0), .6f));
Expand All @@ -89,7 +93,6 @@ public void init() {
} else {
camera = new Camera(getPlayer());
}
System.out.println(camera);
metaData.name = worldData.name;
metaData.world.start(getPlayer());

Expand Down Expand Up @@ -154,7 +157,7 @@ public List<GuiTexture> getGUIs() {

@Override
public TransformComponent getPlayer() {
GameObject player = GameObjectManager.getGameObjectByFirstComponent(ControllableComponent.class);
GameObject player = GameObjectManager.getGameObjectByFirstComponent(PlayerComponent.class);
if(player == null){return new TransformComponent();}
ControllableComponent component = player.getComponent(ControllableComponent.class);
if (component != null) {
Expand Down
Binary file added gameplay/plugins/plugin-hs_gameplay-0.0.3.zip
Binary file not shown.

0 comments on commit 26af347

Please sign in to comment.