move world generation menu functions
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
944a6c93eb
commit
c8ba4c5e5c
@ -1228,6 +1228,7 @@ Add native testing step to jenkins pipeline
|
|||||||
Native code building correctly in jenkins pipeline
|
Native code building correctly in jenkins pipeline
|
||||||
Refactoring native code
|
Refactoring native code
|
||||||
Fix gravity tree not deactivating when body is disabled
|
Fix gravity tree not deactivating when body is disabled
|
||||||
|
Refactoring world menu generators into dedicated class
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package electrosphere.client.ui.menu;
|
package electrosphere.client.ui.menu;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import electrosphere.auth.AuthenticationManager;
|
import electrosphere.auth.AuthenticationManager;
|
||||||
import electrosphere.client.ui.components.InputMacros;
|
import electrosphere.client.ui.components.InputMacros;
|
||||||
import electrosphere.client.ui.menu.mainmenu.MenuGeneratorsKeybind;
|
import electrosphere.client.ui.menu.mainmenu.MenuGeneratorsKeybind;
|
||||||
@ -9,7 +7,6 @@ import electrosphere.client.ui.menu.mainmenu.MenuGeneratorsTitleMenu;
|
|||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.engine.loadingthreads.LoadingThread;
|
import electrosphere.engine.loadingthreads.LoadingThread;
|
||||||
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
|
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
|
||||||
import electrosphere.entity.scene.SceneGenerator;
|
|
||||||
import electrosphere.net.NetUtils;
|
import electrosphere.net.NetUtils;
|
||||||
import electrosphere.renderer.ui.elements.Button;
|
import electrosphere.renderer.ui.elements.Button;
|
||||||
import electrosphere.renderer.ui.elements.Div;
|
import electrosphere.renderer.ui.elements.Div;
|
||||||
@ -17,9 +14,6 @@ import electrosphere.renderer.ui.elements.FormElement;
|
|||||||
import electrosphere.renderer.ui.elements.Label;
|
import electrosphere.renderer.ui.elements.Label;
|
||||||
import electrosphere.renderer.ui.elements.TextInput;
|
import electrosphere.renderer.ui.elements.TextInput;
|
||||||
import electrosphere.renderer.ui.elementtypes.Element;
|
import electrosphere.renderer.ui.elementtypes.Element;
|
||||||
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment;
|
|
||||||
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification;
|
|
||||||
import electrosphere.server.saves.SaveUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generator functions for creating menus
|
* Generator functions for creating menus
|
||||||
@ -35,118 +29,6 @@ public class MenuGenerators {
|
|||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the world selection menu content
|
|
||||||
* @return The menu content
|
|
||||||
*/
|
|
||||||
public static Element createWorldSelectMenu(){
|
|
||||||
FormElement rVal = new FormElement();
|
|
||||||
|
|
||||||
//create save button column
|
|
||||||
Div saveButtonContainer = Div.createCol();
|
|
||||||
saveButtonContainer.setMarginRight(50);
|
|
||||||
List<String> saveNames = SaveUtils.getSaves();
|
|
||||||
for(String saveName : saveNames){
|
|
||||||
if(!saveName.startsWith(".")){
|
|
||||||
|
|
||||||
Div spacer = Div.createDiv();
|
|
||||||
spacer.addChild(Button.createButton(saveName.toUpperCase(), () -> {
|
|
||||||
if(SaveUtils.saveHasWorldFile(saveName.toLowerCase())){
|
|
||||||
//need to log client in
|
|
||||||
Globals.clientUsername = "username";
|
|
||||||
Globals.clientPassword = AuthenticationManager.getHashedString("password");
|
|
||||||
LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME, saveName, Globals.clientUsername, Globals.clientPassword);
|
|
||||||
Globals.RUN_CLIENT = true;
|
|
||||||
Globals.RUN_SERVER = true;
|
|
||||||
Globals.threadManager.start(serverThread);
|
|
||||||
} else {
|
|
||||||
SaveUtils.loadSave(saveName.toLowerCase(), false);
|
|
||||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createSaveCreationMenu());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
spacer.setMarginBottom(30);
|
|
||||||
|
|
||||||
//button (select save)
|
|
||||||
saveButtonContainer.addChild(spacer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Div createButtonContainer = Div.createCol();
|
|
||||||
createButtonContainer.setMarginLeft(50);
|
|
||||||
//button (create)
|
|
||||||
createButtonContainer.addChild(Button.createButton("Create World", () -> {
|
|
||||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldCreationMenu());
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
//layout
|
|
||||||
Div mainLayout = Div.createRow(
|
|
||||||
saveButtonContainer,
|
|
||||||
createButtonContainer
|
|
||||||
);
|
|
||||||
mainLayout.setMarginTop(100);
|
|
||||||
mainLayout.setJustifyContent(YogaJustification.Center);
|
|
||||||
rVal.addChild(mainLayout);
|
|
||||||
|
|
||||||
return rVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* World creation menu
|
|
||||||
* @return The world creation menu element
|
|
||||||
*/
|
|
||||||
public static Element createWorldCreationMenu(){
|
|
||||||
FormElement rVal = new FormElement();
|
|
||||||
|
|
||||||
//text entry (address)
|
|
||||||
Div worldNameInputContainer = Div.createRow();
|
|
||||||
worldNameInputContainer.setMarginBottom(20);
|
|
||||||
TextInput worldNameInput = TextInput.createTextInput();
|
|
||||||
worldNameInput.setMinWidth(100);
|
|
||||||
worldNameInput.setMaxWidthPercent(50);
|
|
||||||
worldNameInput.setText("World name");
|
|
||||||
worldNameInputContainer.addChild(worldNameInput);
|
|
||||||
|
|
||||||
|
|
||||||
//button (create)
|
|
||||||
Div createButtonContainer = Div.createCol();
|
|
||||||
createButtonContainer.setMarginTop(20);
|
|
||||||
createButtonContainer.addChild(Button.createButton("Create", () -> {
|
|
||||||
String saveName = worldNameInput.getText();
|
|
||||||
//create save dir
|
|
||||||
SaveUtils.createOrOverwriteSave(saveName, SceneGenerator.createProceduralSceneFile(saveName));
|
|
||||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
//layout content
|
|
||||||
Div mainLayout = Div.createCol(
|
|
||||||
worldNameInputContainer,
|
|
||||||
createButtonContainer
|
|
||||||
);
|
|
||||||
mainLayout.setMarginTop(300);
|
|
||||||
mainLayout.setAlignItems(YogaAlignment.Center);
|
|
||||||
rVal.addChild(mainLayout);
|
|
||||||
|
|
||||||
return rVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Element createSaveCreationMenu(){
|
|
||||||
FormElement rVal = new FormElement();
|
|
||||||
|
|
||||||
//button (save)
|
|
||||||
rVal.addChild(Button.createButton("Save", () -> {
|
|
||||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
|
|
||||||
throw new UnsupportedOperationException("Need to update to use new save flow");
|
|
||||||
}));
|
|
||||||
|
|
||||||
//button (cancel)
|
|
||||||
rVal.addChild(Button.createButton("Cancel", () -> {
|
|
||||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
|
|
||||||
}));
|
|
||||||
|
|
||||||
return rVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Element createCharacterCreationMenu(){
|
public static Element createCharacterCreationMenu(){
|
||||||
FormElement rVal = new FormElement();
|
FormElement rVal = new FormElement();
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package electrosphere.client.ui.menu.mainmenu;
|
package electrosphere.client.ui.menu.mainmenu;
|
||||||
|
|
||||||
import electrosphere.client.ui.components.CharacterCustomizer;
|
import electrosphere.client.ui.components.CharacterCustomizer;
|
||||||
import electrosphere.client.ui.menu.MenuGenerators;
|
|
||||||
import electrosphere.client.ui.menu.WindowUtils;
|
import electrosphere.client.ui.menu.WindowUtils;
|
||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.entity.types.creature.CreatureTemplate;
|
import electrosphere.entity.types.creature.CreatureTemplate;
|
||||||
@ -28,7 +27,7 @@ public class MenuGeneratorsMultiplayer {
|
|||||||
createButton.addChild(createLabel);
|
createButton.addChild(createLabel);
|
||||||
rVal.addChild(createButton);
|
rVal.addChild(createButton);
|
||||||
createButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
|
createButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
|
||||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldCreationMenu());
|
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldCreationMenu());
|
||||||
return false;
|
return false;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class MenuGeneratorsTitleMenu {
|
|||||||
|
|
||||||
//button (multiplayer)
|
//button (multiplayer)
|
||||||
optionPanel.addChild(Button.createButtonCentered("Singleplayer", 1.0f, () -> {
|
optionPanel.addChild(Button.createButtonCentered("Singleplayer", 1.0f, () -> {
|
||||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
|
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldSelectMenu());
|
||||||
}).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE));
|
}).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE));
|
||||||
|
|
||||||
//button (multiplayer)
|
//button (multiplayer)
|
||||||
|
|||||||
@ -0,0 +1,139 @@
|
|||||||
|
package electrosphere.client.ui.menu.mainmenu;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import electrosphere.auth.AuthenticationManager;
|
||||||
|
import electrosphere.client.ui.menu.WindowUtils;
|
||||||
|
import electrosphere.engine.Globals;
|
||||||
|
import electrosphere.engine.loadingthreads.LoadingThread;
|
||||||
|
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
|
||||||
|
import electrosphere.entity.scene.SceneGenerator;
|
||||||
|
import electrosphere.renderer.ui.elements.Button;
|
||||||
|
import electrosphere.renderer.ui.elements.Div;
|
||||||
|
import electrosphere.renderer.ui.elements.FormElement;
|
||||||
|
import electrosphere.renderer.ui.elements.TextInput;
|
||||||
|
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment;
|
||||||
|
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification;
|
||||||
|
import electrosphere.renderer.ui.elementtypes.Element;
|
||||||
|
import electrosphere.server.saves.SaveUtils;
|
||||||
|
|
||||||
|
public class MenuWorldSelect {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the world selection menu content
|
||||||
|
* @return The menu content
|
||||||
|
*/
|
||||||
|
public static Element createWorldSelectMenu(){
|
||||||
|
FormElement rVal = new FormElement();
|
||||||
|
|
||||||
|
//create save button column
|
||||||
|
Div saveButtonContainer = Div.createCol();
|
||||||
|
saveButtonContainer.setMarginRight(50);
|
||||||
|
List<String> saveNames = SaveUtils.getSaves();
|
||||||
|
for(String saveName : saveNames){
|
||||||
|
if(!saveName.startsWith(".")){
|
||||||
|
|
||||||
|
Div spacer = Div.createDiv();
|
||||||
|
spacer.addChild(Button.createButton(saveName.toUpperCase(), () -> {
|
||||||
|
if(SaveUtils.saveHasWorldFile(saveName.toLowerCase())){
|
||||||
|
//need to log client in
|
||||||
|
Globals.clientUsername = "username";
|
||||||
|
Globals.clientPassword = AuthenticationManager.getHashedString("password");
|
||||||
|
LoadingThread serverThread = new LoadingThread(LoadingThreadType.MAIN_GAME, saveName, Globals.clientUsername, Globals.clientPassword);
|
||||||
|
Globals.RUN_CLIENT = true;
|
||||||
|
Globals.RUN_SERVER = true;
|
||||||
|
Globals.threadManager.start(serverThread);
|
||||||
|
} else {
|
||||||
|
SaveUtils.loadSave(saveName.toLowerCase(), false);
|
||||||
|
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createSaveCreationMenu());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
spacer.setMarginBottom(30);
|
||||||
|
|
||||||
|
//button (select save)
|
||||||
|
saveButtonContainer.addChild(spacer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Div createButtonContainer = Div.createCol();
|
||||||
|
createButtonContainer.setMarginLeft(50);
|
||||||
|
//button (create)
|
||||||
|
createButtonContainer.addChild(Button.createButton("Create World", () -> {
|
||||||
|
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldCreationMenu());
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
//layout
|
||||||
|
Div mainLayout = Div.createRow(
|
||||||
|
saveButtonContainer,
|
||||||
|
createButtonContainer
|
||||||
|
);
|
||||||
|
mainLayout.setMarginTop(100);
|
||||||
|
mainLayout.setJustifyContent(YogaJustification.Center);
|
||||||
|
rVal.addChild(mainLayout);
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* World creation menu
|
||||||
|
* @return The world creation menu element
|
||||||
|
*/
|
||||||
|
public static Element createWorldCreationMenu(){
|
||||||
|
FormElement rVal = new FormElement();
|
||||||
|
|
||||||
|
//text entry (address)
|
||||||
|
Div worldNameInputContainer = Div.createRow();
|
||||||
|
worldNameInputContainer.setMarginBottom(20);
|
||||||
|
TextInput worldNameInput = TextInput.createTextInput();
|
||||||
|
worldNameInput.setMinWidth(100);
|
||||||
|
worldNameInput.setMaxWidthPercent(50);
|
||||||
|
worldNameInput.setText("World name");
|
||||||
|
worldNameInputContainer.addChild(worldNameInput);
|
||||||
|
|
||||||
|
|
||||||
|
//button (create)
|
||||||
|
Div createButtonContainer = Div.createCol();
|
||||||
|
createButtonContainer.setMarginTop(20);
|
||||||
|
createButtonContainer.addChild(Button.createButton("Create", () -> {
|
||||||
|
String saveName = worldNameInput.getText();
|
||||||
|
//create save dir
|
||||||
|
SaveUtils.createOrOverwriteSave(saveName, SceneGenerator.createProceduralSceneFile(saveName));
|
||||||
|
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldSelectMenu());
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
//layout content
|
||||||
|
Div mainLayout = Div.createCol(
|
||||||
|
worldNameInputContainer,
|
||||||
|
createButtonContainer
|
||||||
|
);
|
||||||
|
mainLayout.setMarginTop(300);
|
||||||
|
mainLayout.setAlignItems(YogaAlignment.Center);
|
||||||
|
rVal.addChild(mainLayout);
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save creation menu
|
||||||
|
* @return The save creation menu element
|
||||||
|
*/
|
||||||
|
public static Element createSaveCreationMenu(){
|
||||||
|
FormElement rVal = new FormElement();
|
||||||
|
|
||||||
|
//button (save)
|
||||||
|
rVal.addChild(Button.createButton("Save", () -> {
|
||||||
|
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldSelectMenu());
|
||||||
|
throw new UnsupportedOperationException("Need to update to use new save flow");
|
||||||
|
}));
|
||||||
|
|
||||||
|
//button (cancel)
|
||||||
|
rVal.addChild(Button.createButton("Cancel", () -> {
|
||||||
|
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldSelectMenu());
|
||||||
|
}));
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -18,6 +18,11 @@ import org.joml.Vector3i;
|
|||||||
*/
|
*/
|
||||||
public class ServerWorldData {
|
public class ServerWorldData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The size of the procedural world
|
||||||
|
*/
|
||||||
|
public static final int PROCEDURAL_WORLD_SIZE = 2000;
|
||||||
|
|
||||||
public static enum WorldType {
|
public static enum WorldType {
|
||||||
GAME_WORLD,
|
GAME_WORLD,
|
||||||
ARENA_WORLD,
|
ARENA_WORLD,
|
||||||
|
|||||||
@ -131,12 +131,6 @@ public class ServerFluidManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a fluid model for the manager
|
|
||||||
*/
|
|
||||||
public void generate(){
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the fluid model backing this manager to a save file
|
* Saves the fluid model backing this manager to a save file
|
||||||
* @param saveName The name of the save
|
* @param saveName The name of the save
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import electrosphere.server.db.DatabaseUtils;
|
|||||||
import electrosphere.server.fluid.generation.DefaultFluidGenerator;
|
import electrosphere.server.fluid.generation.DefaultFluidGenerator;
|
||||||
import electrosphere.server.fluid.manager.ServerFluidManager;
|
import electrosphere.server.fluid.manager.ServerFluidManager;
|
||||||
import electrosphere.server.terrain.generation.DefaultChunkGenerator;
|
import electrosphere.server.terrain.generation.DefaultChunkGenerator;
|
||||||
import electrosphere.server.terrain.generation.OverworldChunkGenerator;
|
import electrosphere.server.terrain.generation.TestGenerationChunkGenerator;
|
||||||
import electrosphere.server.terrain.manager.ServerTerrainManager;
|
import electrosphere.server.terrain.manager.ServerTerrainManager;
|
||||||
import electrosphere.util.FileUtils;
|
import electrosphere.util.FileUtils;
|
||||||
|
|
||||||
@ -112,15 +112,14 @@ public class SaveUtils {
|
|||||||
//generate terrain and save to disk
|
//generate terrain and save to disk
|
||||||
//
|
//
|
||||||
//Server world data
|
//Server world data
|
||||||
ServerWorldData serverWorldData = ServerWorldData.createGriddedRealmWorldData(2000);
|
ServerWorldData serverWorldData = ServerWorldData.createGriddedRealmWorldData(ServerWorldData.PROCEDURAL_WORLD_SIZE);
|
||||||
FileUtils.serializeObjectToSavePath(saveName, "./world.json", serverWorldData);
|
FileUtils.serializeObjectToSavePath(saveName, "./world.json", serverWorldData);
|
||||||
//terrain manager
|
//terrain manager
|
||||||
ServerTerrainManager serverTerrainManager = new ServerTerrainManager(serverWorldData, 0, new OverworldChunkGenerator());
|
ServerTerrainManager serverTerrainManager = new ServerTerrainManager(serverWorldData, 0, new TestGenerationChunkGenerator(serverWorldData, false));
|
||||||
serverTerrainManager.generate();
|
serverTerrainManager.generate();
|
||||||
serverTerrainManager.save(saveName);
|
serverTerrainManager.save(saveName);
|
||||||
//fluid manager
|
//fluid manager
|
||||||
ServerFluidManager serverFluidManager = new ServerFluidManager(serverWorldData, serverTerrainManager, 0, new DefaultFluidGenerator());
|
ServerFluidManager serverFluidManager = new ServerFluidManager(serverWorldData, serverTerrainManager, 0, new DefaultFluidGenerator());
|
||||||
serverFluidManager.generate();
|
|
||||||
serverFluidManager.save(saveName);
|
serverFluidManager.save(saveName);
|
||||||
} else {
|
} else {
|
||||||
//just save to disk
|
//just save to disk
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user