From 1d11585fcd8c389d9feed3d888080211efa1e20e Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 8 Sep 2020 22:57:29 -0400 Subject: [PATCH] FIxes --- .../command/CommandIrisStudioExplorer.java | 30 +++++--- .../CommandIrisStudioExplorerGenerator.java | 77 +++++++++++++++++++ .../com/volmit/iris/gui/NoiseExplorer.java | 66 +++++++++++----- 3 files changed, 145 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisStudioExplorerGenerator.java diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioExplorer.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioExplorer.java index ed2cbca2d..fc7a68f87 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioExplorer.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioExplorer.java @@ -3,11 +3,15 @@ package com.volmit.iris.command; import com.volmit.iris.Iris; import com.volmit.iris.IrisSettings; import com.volmit.iris.gui.NoiseExplorer; +import com.volmit.iris.util.Command; import com.volmit.iris.util.MortarCommand; import com.volmit.iris.util.MortarSender; public class CommandIrisStudioExplorer extends MortarCommand { + @Command + private CommandIrisStudioExplorerGenerator generator; + public CommandIrisStudioExplorer() { super("noise", "nmap"); @@ -19,20 +23,28 @@ public class CommandIrisStudioExplorer extends MortarCommand @Override public boolean handle(MortarSender sender, String[] args) { - if(!IrisSettings.get().isStudio()) + if(args.length != 0) { - sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json"); - return true; + printHelp(sender); } - if(!IrisSettings.get().isUseServerLaunchedGuis()) + else { - sender.sendMessage("To use Iris Guis, please enable serverLaunchedGuis in Iris/settings.json"); - return true; - } + if(!IrisSettings.get().isStudio()) + { + sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json"); + return true; + } - NoiseExplorer.launch(); - sender.sendMessage("Opening Noise Explorer!"); + if(!IrisSettings.get().isUseServerLaunchedGuis()) + { + sender.sendMessage("To use Iris Guis, please enable serverLaunchedGuis in Iris/settings.json"); + return true; + } + + NoiseExplorer.launch(); + sender.sendMessage("Opening Noise Explorer!"); + } return true; } diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioExplorerGenerator.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioExplorerGenerator.java new file mode 100644 index 000000000..0067e0a4e --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioExplorerGenerator.java @@ -0,0 +1,77 @@ +package com.volmit.iris.command; + +import com.volmit.iris.Iris; +import com.volmit.iris.IrisSettings; +import com.volmit.iris.gui.NoiseExplorer; +import com.volmit.iris.object.IrisGenerator; +import com.volmit.iris.util.MortarCommand; +import com.volmit.iris.util.MortarSender; + +public class CommandIrisStudioExplorerGenerator extends MortarCommand +{ + public CommandIrisStudioExplorerGenerator() + { + super("generator", "gen", "g"); + setDescription("Explore different generators"); + requiresPermission(Iris.perm.studio); + setCategory("World"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!IrisSettings.get().isStudio()) + { + sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json"); + return true; + } + + if(!IrisSettings.get().isUseServerLaunchedGuis()) + { + sender.sendMessage("To use Iris Guis, please enable serverLaunchedGuis in Iris/settings.json"); + return true; + } + + if(Iris.proj.getCurrentProject() == null) + { + sender.sendMessage("No project is open"); + return true; + } + + if(args.length == 0) + { + sender.sendMessage("Provide a generator name"); + return true; + } + + else + { + String g = args[0]; + IrisGenerator b = Iris.proj.getCurrentProject().getData().getGeneratorLoader().load(g); + + if(b != null) + { + NoiseExplorer.launch((x, z) -> + { + return b.getHeight(x, z, Iris.proj.getCurrentProject().getMasterRandom().nextParallelRNG(3245).lmax()); + }, "Gen: " + b.getLoadKey()); + + sender.sendMessage("Opening Noise Explorer for gen " + b.getLoadKey()); + return true; + } + + else + { + sender.sendMessage("Invalid Generator"); + } + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return ""; + } +} diff --git a/src/main/java/com/volmit/iris/gui/NoiseExplorer.java b/src/main/java/com/volmit/iris/gui/NoiseExplorer.java index 98a2dbcca..7c649fbbd 100644 --- a/src/main/java/com/volmit/iris/gui/NoiseExplorer.java +++ b/src/main/java/com/volmit/iris/gui/NoiseExplorer.java @@ -3,7 +3,6 @@ package com.volmit.iris.gui; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; -import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; @@ -56,7 +55,7 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener int[][] co; int w = 0; int h = 0; - static Function2 renderer; + static Function2 generator; static double oxp = 0; static double ozp = 0; double ox = 0; @@ -207,25 +206,16 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener int zz = z; gx.queue("a", () -> { - if(renderer != null) + double n = generator != null ? generator.apply(Double.valueOf((xx * ascale) + oxp), Double.valueOf((zz * ascale) + ozp)) : cng.noise((xx * ascale) + oxp, tz, (zz * ascale) + ozp); + + if(n > 1 || n < 0) { - co[xx][zz] = renderer.apply((xx * ascale) + oxp, (zz * ascale) + ozp).getRGB(); + return; } - else - { - double n = cng.noise((xx * ascale) + oxp, tz, (zz * ascale) + ozp); - - if(n > 1 || n < 0) - { - System.out.println("EXCEEDED " + n); - return; - } - - Color color = colorMode ? Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n), 1f - (float) n) : Color.getHSBColor(0f, 0f, (float) n); - int rgb = color.getRGB(); - co[xx][zz] = rgb; - } + Color color = colorMode ? Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n), 1f - (float) n) : Color.getHSBColor(0f, 0f, (float) n); + int rgb = color.getRGB(); + co[xx][zz] = rgb; }); } @@ -274,6 +264,34 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener }); } + private static void createAndShowGUI(Function2 gen, String genName) + { + JFrame frame = new JFrame("Noise Explorer: " + genName); + NoiseExplorer nv = new NoiseExplorer(); + frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + JLayeredPane pane = new JLayeredPane(); + nv.setSize(new Dimension(1440, 820)); + pane.add(nv, 1, 0); + NoiseExplorer.generator = gen; + frame.add(pane); + File file = Iris.getCached("Iris Icon", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/icon.png"); + + if(file != null) + { + try + { + frame.setIconImage(ImageIO.read(file)); + } + + catch(IOException e) + { + + } + } + frame.setSize(1440, 820); + frame.setVisible(true); + } + private static void createAndShowGUI() { JFrame frame = new JFrame("Noise Explorer"); @@ -289,7 +307,6 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener { @SuppressWarnings("unchecked") String b = (String) (((JComboBox) e.getSource()).getSelectedItem()); - renderer = null; NoiseStyle s = NoiseStyle.valueOf(b); nv.cng = s.create(RNG.r.nextParallelRNG(RNG.r.imax())); } @@ -319,6 +336,17 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener frame.setVisible(true); } + public static void launch(Function2 gen, String genName) + { + EventQueue.invokeLater(new Runnable() + { + public void run() + { + createAndShowGUI(gen, genName); + } + }); + } + public static void launch() { EventQueue.invokeLater(new Runnable()