This commit is contained in:
Daniel Mills 2020-09-08 22:57:29 -04:00
parent b0d8b9a078
commit 1d11585fcd
3 changed files with 145 additions and 28 deletions

View File

@ -3,11 +3,15 @@ package com.volmit.iris.command;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings; import com.volmit.iris.IrisSettings;
import com.volmit.iris.gui.NoiseExplorer; import com.volmit.iris.gui.NoiseExplorer;
import com.volmit.iris.util.Command;
import com.volmit.iris.util.MortarCommand; import com.volmit.iris.util.MortarCommand;
import com.volmit.iris.util.MortarSender; import com.volmit.iris.util.MortarSender;
public class CommandIrisStudioExplorer extends MortarCommand public class CommandIrisStudioExplorer extends MortarCommand
{ {
@Command
private CommandIrisStudioExplorerGenerator generator;
public CommandIrisStudioExplorer() public CommandIrisStudioExplorer()
{ {
super("noise", "nmap"); super("noise", "nmap");
@ -19,20 +23,28 @@ public class CommandIrisStudioExplorer extends MortarCommand
@Override @Override
public boolean handle(MortarSender sender, String[] args) 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"); printHelp(sender);
return true;
} }
if(!IrisSettings.get().isUseServerLaunchedGuis()) else
{ {
sender.sendMessage("To use Iris Guis, please enable serverLaunchedGuis in Iris/settings.json"); if(!IrisSettings.get().isStudio())
return true; {
} sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json");
return true;
}
NoiseExplorer.launch(); if(!IrisSettings.get().isUseServerLaunchedGuis())
sender.sendMessage("Opening Noise Explorer!"); {
sender.sendMessage("To use Iris Guis, please enable serverLaunchedGuis in Iris/settings.json");
return true;
}
NoiseExplorer.launch();
sender.sendMessage("Opening Noise Explorer!");
}
return true; return true;
} }

View File

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

View File

@ -3,7 +3,6 @@ package com.volmit.iris.gui;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
@ -56,7 +55,7 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener
int[][] co; int[][] co;
int w = 0; int w = 0;
int h = 0; int h = 0;
static Function2<Double, Double, Color> renderer; static Function2<Double, Double, Double> generator;
static double oxp = 0; static double oxp = 0;
static double ozp = 0; static double ozp = 0;
double ox = 0; double ox = 0;
@ -207,25 +206,16 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener
int zz = z; int zz = z;
gx.queue("a", () -> 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 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();
double n = cng.noise((xx * ascale) + oxp, tz, (zz * ascale) + ozp); co[xx][zz] = rgb;
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;
}
}); });
} }
@ -274,6 +264,34 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener
}); });
} }
private static void createAndShowGUI(Function2<Double, Double, Double> 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() private static void createAndShowGUI()
{ {
JFrame frame = new JFrame("Noise Explorer"); JFrame frame = new JFrame("Noise Explorer");
@ -289,7 +307,6 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
String b = (String) (((JComboBox<String>) e.getSource()).getSelectedItem()); String b = (String) (((JComboBox<String>) e.getSource()).getSelectedItem());
renderer = null;
NoiseStyle s = NoiseStyle.valueOf(b); NoiseStyle s = NoiseStyle.valueOf(b);
nv.cng = s.create(RNG.r.nextParallelRNG(RNG.r.imax())); nv.cng = s.create(RNG.r.nextParallelRNG(RNG.r.imax()));
} }
@ -319,6 +336,17 @@ public class NoiseExplorer extends JPanel implements MouseWheelListener
frame.setVisible(true); frame.setVisible(true);
} }
public static void launch(Function2<Double, Double, Double> gen, String genName)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
createAndShowGUI(gen, genName);
}
});
}
public static void launch() public static void launch()
{ {
EventQueue.invokeLater(new Runnable() EventQueue.invokeLater(new Runnable()