Add ResourceLoader texture loading functionality and update DiceOS to use it
This commit is contained in:
@@ -18,6 +18,7 @@ import java.util.List;
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class DiceOS extends ApplicationAdapter {
|
||||
private final ResourceLoader resourceLoader;
|
||||
private final DisplayService display;
|
||||
private final CursorService cursorService;
|
||||
private final List<OnStartup> startupTasks;
|
||||
@@ -36,7 +37,7 @@ public class DiceOS extends ApplicationAdapter {
|
||||
log.info("DiceOS starting...");
|
||||
background = new Texture("src/main/resources/background.png");
|
||||
clouds = new Texture("src/main/resources/clouds.png");
|
||||
border = new Texture("src/main/resources/border.png");
|
||||
border = resourceLoader.loadTexture("system/border.png");
|
||||
loadMenubar();
|
||||
|
||||
screenViewport = new ScreenViewport();
|
||||
@@ -52,7 +53,7 @@ public class DiceOS extends ApplicationAdapter {
|
||||
}
|
||||
|
||||
private void loadMenubar() {
|
||||
var texture = new Texture("src/main/resources/menubar.png");
|
||||
var texture = resourceLoader.loadTexture("system/menubar.png");
|
||||
menubar = new NinePatch(texture, 9, 9, 15, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package be.seeseemelk.diceos.system;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import io.avaje.inject.Component;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -12,8 +13,13 @@ import java.util.Map;
|
||||
@Component
|
||||
public class ResourceLoader {
|
||||
private final Map<String, Pixmap> pixmaps = new HashMap<>();
|
||||
private final Map<String, Texture> textures = new HashMap<>();
|
||||
|
||||
public Pixmap loadPixmap(String path) {
|
||||
return pixmaps.computeIfAbsent(path, p -> new Pixmap(Gdx.files.internal(p)));
|
||||
}
|
||||
|
||||
public Texture loadTexture(String path) {
|
||||
return textures.computeIfAbsent(path, p -> new Texture(Gdx.files.internal(p)));
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 110 B After Width: | Height: | Size: 110 B |
|
Before Width: | Height: | Size: 305 B After Width: | Height: | Size: 305 B |
Reference in New Issue
Block a user