move world generation menu functions
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-03 14:05:54 -05:00
parent 944a6c93eb
commit c8ba4c5e5c
8 changed files with 150 additions and 131 deletions

View File

@ -1228,6 +1228,7 @@ Add native testing step to jenkins pipeline
Native code building correctly in jenkins pipeline
Refactoring native code
Fix gravity tree not deactivating when body is disabled
Refactoring world menu generators into dedicated class

View File

@ -1,7 +1,5 @@
package electrosphere.client.ui.menu;
import java.util.List;
import electrosphere.auth.AuthenticationManager;
import electrosphere.client.ui.components.InputMacros;
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.loadingthreads.LoadingThread;
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
import electrosphere.entity.scene.SceneGenerator;
import electrosphere.net.NetUtils;
import electrosphere.renderer.ui.elements.Button;
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.TextInput;
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
@ -35,118 +29,6 @@ public class MenuGenerators {
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(){
FormElement rVal = new FormElement();

View File

@ -1,7 +1,6 @@
package electrosphere.client.ui.menu.mainmenu;
import electrosphere.client.ui.components.CharacterCustomizer;
import electrosphere.client.ui.menu.MenuGenerators;
import electrosphere.client.ui.menu.WindowUtils;
import electrosphere.engine.Globals;
import electrosphere.entity.types.creature.CreatureTemplate;
@ -28,7 +27,7 @@ public class MenuGeneratorsMultiplayer {
createButton.addChild(createLabel);
rVal.addChild(createButton);
createButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldCreationMenu());
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldCreationMenu());
return false;
}});

View File

@ -48,7 +48,7 @@ public class MenuGeneratorsTitleMenu {
//button (multiplayer)
optionPanel.addChild(Button.createButtonCentered("Singleplayer", 1.0f, () -> {
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
WindowUtils.replaceMainMenuContents(MenuWorldSelect.createWorldSelectMenu());
}).setOnClickAudio(AssetDataStrings.UI_TONE_BUTTON_TITLE));
//button (multiplayer)

View File

@ -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;
}
}

View File

@ -18,6 +18,11 @@ import org.joml.Vector3i;
*/
public class ServerWorldData {
/**
* The size of the procedural world
*/
public static final int PROCEDURAL_WORLD_SIZE = 2000;
public static enum WorldType {
GAME_WORLD,
ARENA_WORLD,

View File

@ -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
* @param saveName The name of the save

View File

@ -12,7 +12,7 @@ import electrosphere.server.db.DatabaseUtils;
import electrosphere.server.fluid.generation.DefaultFluidGenerator;
import electrosphere.server.fluid.manager.ServerFluidManager;
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.util.FileUtils;
@ -112,15 +112,14 @@ public class SaveUtils {
//generate terrain and save to disk
//
//Server world data
ServerWorldData serverWorldData = ServerWorldData.createGriddedRealmWorldData(2000);
ServerWorldData serverWorldData = ServerWorldData.createGriddedRealmWorldData(ServerWorldData.PROCEDURAL_WORLD_SIZE);
FileUtils.serializeObjectToSavePath(saveName, "./world.json", serverWorldData);
//terrain manager
ServerTerrainManager serverTerrainManager = new ServerTerrainManager(serverWorldData, 0, new OverworldChunkGenerator());
ServerTerrainManager serverTerrainManager = new ServerTerrainManager(serverWorldData, 0, new TestGenerationChunkGenerator(serverWorldData, false));
serverTerrainManager.generate();
serverTerrainManager.save(saveName);
//fluid manager
ServerFluidManager serverFluidManager = new ServerFluidManager(serverWorldData, serverTerrainManager, 0, new DefaultFluidGenerator());
serverFluidManager.generate();
serverFluidManager.save(saveName);
} else {
//just save to disk