Custom background renderer support for mods

This commit is contained in:
Anuken
2021-09-17 21:20:16 -04:00
parent 263850624a
commit cdb12a381d
2 changed files with 11 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ public class Renderer implements ApplicationListener{
/** minZoom = zooming out, maxZoom = zooming in */
public float minZoom = 1.5f, maxZoom = 6f;
public Seq<EnvRenderer> envRenderers = new Seq<>();
public ObjectMap<String, Runnable> 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(){

View File

@@ -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 */