Skip to content

Commit

Permalink
feat: update preview on manual seed change
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrueckert committed Oct 15, 2023
1 parent a0ccb20 commit 194f87d
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.terasology.engine.config.Config;
import org.terasology.engine.context.Context;
import org.terasology.engine.core.GameEngine;
import org.terasology.engine.core.Time;
import org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler;
import org.terasology.engine.core.modes.StateLoading;
import org.terasology.engine.core.module.ModuleManager;
Expand Down Expand Up @@ -101,12 +102,16 @@ public class UniverseSetupScreen extends CoreScreenLayer implements UISliderOnCh
@In
private Context context;

@In
private Time time;

private ModuleEnvironment environment;
private ModuleAwareAssetTypeManager assetTypeManager;
private UISlider zoomSlider;
private Texture texture;
private PreviewGenerator previewGen;
private UIImage previewImage;
private long seedLastModified = Long.MAX_VALUE;

@Override
public void initialise() {
Expand Down Expand Up @@ -187,6 +192,7 @@ public String get() {
public void set(String value) {
//setSeed(value);
context.get(UniverseWrapper.class).setSeed(value);
seedLastModified = time.getRealTimeInMs();
//context.get(UniverseWrapper.class).getWorldGenerator().setWorldSeed(context.get(UniverseWrapper.class).getSeed());
}
});
Expand Down Expand Up @@ -245,6 +251,18 @@ public void set(String value) {
});
}

@Override
public void update(float delta) {
super.update(delta);

if (seedLastModified < time.getRealTimeInMs() - 1000) {
UniverseWrapper universeWrapper = context.get(UniverseWrapper.class);
universeWrapper.getWorldGenerator().setWorldSeed(universeWrapper.getSeed());
updatePreview();
seedLastModified = Long.MAX_VALUE;
}
}

private void setSeed(String value) {
UniverseWrapper universeWrapper = context.get(UniverseWrapper.class);
universeWrapper.setSeed(value);
Expand Down

0 comments on commit 194f87d

Please sign in to comment.