From cdb12a381dde127267cca607401999ccdac74575 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 17 Sep 2021 21:20:16 -0400 Subject: [PATCH] Custom background renderer support for mods --- core/src/mindustry/core/Renderer.java | 9 +++++++++ core/src/mindustry/game/Rules.java | 2 ++ 2 files changed, 11 insertions(+) diff --git a/core/src/mindustry/core/Renderer.java b/core/src/mindustry/core/Renderer.java index ae8fa03536..9738ce1133 100644 --- a/core/src/mindustry/core/Renderer.java +++ b/core/src/mindustry/core/Renderer.java @@ -50,6 +50,7 @@ public class Renderer implements ApplicationListener{ /** minZoom = zooming out, maxZoom = zooming in */ public float minZoom = 1.5f, maxZoom = 6f; public Seq envRenderers = new Seq<>(); + public ObjectMap customBackgrounds = new ObjectMap<>(); public TextureRegion[] bubbles = new TextureRegion[16], splashes = new TextureRegion[12]; private @Nullable CoreBuild landCore; @@ -90,6 +91,10 @@ public class Renderer implements ApplicationListener{ envRenderers.add(new EnvRenderer(mask, render)); } + public void addCustomBackground(String name, Runnable render){ + customBackgrounds.put(name, render); + } + @Override public void init(){ planets = new PlanetRenderer(); @@ -386,6 +391,10 @@ public class Renderer implements ApplicationListener{ Draw.rect(Draw.wrap(backgroundBuffer.getTexture()), camera.position.x, camera.position.y, drawSize, -drawSize); } + if(state.rules.customBackgroundCallback != null && customBackgrounds.containsKey(state.rules.customBackgroundCallback)){ + customBackgrounds.get(state.rules.customBackgroundCallback).run(); + } + } void updateLandParticles(){ diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index 60d3748ea2..c9edb5722b 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -122,6 +122,8 @@ public class Rules{ public boolean borderDarkness = true; /** special tags for additional info. */ public StringMap tags = new StringMap(); + /** Name of callback to call for background rendering in mods; see Renderer#addCustomBackground. Runs last. */ + public @Nullable String customBackgroundCallback; /** path to background texture with extension (e.g. "sprites/space.png")*/ public @Nullable String backgroundTexture; /** background texture move speed scaling - bigger numbers mean slower movement */