diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a3417b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/out/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/libraries/skunkworks.xml b/.idea/libraries/skunkworks.xml new file mode 100644 index 0000000..1dd35c0 --- /dev/null +++ b/.idea/libraries/skunkworks.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..69a4127 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/9slice-2.png b/9slice-2.png new file mode 100644 index 0000000..e26ebe0 Binary files /dev/null and b/9slice-2.png differ diff --git a/fonts/ega-8x14.png b/fonts/ega-8x14.png new file mode 100644 index 0000000..5da0d32 Binary files /dev/null and b/fonts/ega-8x14.png differ diff --git a/fonts/thin-6x12.png b/fonts/thin-6x12.png new file mode 100644 index 0000000..6521b92 Binary files /dev/null and b/fonts/thin-6x12.png differ diff --git a/skunkstream.iml b/skunkstream.iml new file mode 100644 index 0000000..8c8be27 --- /dev/null +++ b/skunkstream.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/danitheskunk/skunkstream/IElement.java b/src/com/danitheskunk/skunkstream/IElement.java new file mode 100644 index 0000000..be6a1df --- /dev/null +++ b/src/com/danitheskunk/skunkstream/IElement.java @@ -0,0 +1,7 @@ +package com.danitheskunk.skunkstream; + +import com.danitheskunk.skunkworks.gfx.IRenderContext; + +public interface IElement { + void render(IRenderContext rc); +} diff --git a/src/com/danitheskunk/skunkstream/Image.java b/src/com/danitheskunk/skunkstream/Image.java new file mode 100644 index 0000000..4434293 --- /dev/null +++ b/src/com/danitheskunk/skunkstream/Image.java @@ -0,0 +1,34 @@ +package com.danitheskunk.skunkstream; + +import com.danitheskunk.skunkworks.Recti; +import com.danitheskunk.skunkworks.Vec2i; +import com.danitheskunk.skunkworks.gfx.Color; +import com.danitheskunk.skunkworks.gfx.IRenderContext; +import com.danitheskunk.skunkworks.gfx.ITexture; + +public class Image implements IElement { + private final Vec2i pos; + private final ITexture texture; + private final Vec2i size; + private final Color color; + + public Image(Vec2i pos, ITexture texture, Vec2i size, Color color) { + this.pos = pos; + this.texture = texture; + this.size = size; + this.color = color; + } + + @Override + public void render(IRenderContext rc) { + if(size == Vec2i.ZERO) { + rc.drawTexture(pos, texture, color); + } else { + rc.drawTextureRectangle(new Recti(pos, size), + texture, + color, + false + ); + } + } +} diff --git a/src/com/danitheskunk/skunkstream/Label.java b/src/com/danitheskunk/skunkstream/Label.java new file mode 100644 index 0000000..dd0008e --- /dev/null +++ b/src/com/danitheskunk/skunkstream/Label.java @@ -0,0 +1,30 @@ +package com.danitheskunk.skunkstream; + +import com.danitheskunk.skunkworks.Vec2i; +import com.danitheskunk.skunkworks.gfx.Color; +import com.danitheskunk.skunkworks.gfx.IRenderContext; +import com.danitheskunk.skunkworks.gfx.font.IFont; + +public class Label implements IElement { + private final Vec2i pos; + private final String text; + private final IFont font; + private final Color color; + + public Label(Vec2i pos, String text, IFont font, Color color) { + this.pos = pos; + this.text = text; + this.font = font; + this.color = color; + } + + @Override + public void render(IRenderContext rc) { + rc.drawString( + pos, + text, + font, + color + ); + } +} diff --git a/src/com/danitheskunk/skunkstream/NineSlice.java b/src/com/danitheskunk/skunkstream/NineSlice.java new file mode 100644 index 0000000..0cfbb21 --- /dev/null +++ b/src/com/danitheskunk/skunkstream/NineSlice.java @@ -0,0 +1,23 @@ +package com.danitheskunk.skunkstream; + +import com.danitheskunk.skunkworks.Recti; +import com.danitheskunk.skunkworks.Vec2i; +import com.danitheskunk.skunkworks.gfx.IRenderContext; + +public class NineSlice implements IElement { + private final Vec2i pos; + private final com.danitheskunk.skunkworks.gfx.NineSlice nineSlice; + private final Vec2i size; + + public NineSlice(Vec2i pos, + com.danitheskunk.skunkworks.gfx.NineSlice nineSlice, Vec2i size) { + this.pos = pos; + this.nineSlice = nineSlice; + this.size = size; + } + + @Override + public void render(IRenderContext rc) { + rc.drawNineSlice(nineSlice, new Recti(pos, size)); + } +} diff --git a/src/com/danitheskunk/skunkstream/Skunkstream.java b/src/com/danitheskunk/skunkstream/Skunkstream.java new file mode 100644 index 0000000..eac8723 --- /dev/null +++ b/src/com/danitheskunk/skunkstream/Skunkstream.java @@ -0,0 +1,87 @@ +package com.danitheskunk.skunkstream; + +import com.danitheskunk.skunkworks.BaseGame; +import com.danitheskunk.skunkworks.Data; +import com.danitheskunk.skunkworks.Vec2i; +import com.danitheskunk.skunkworks.gfx.IRenderContext; +import com.danitheskunk.skunkworks.gfx.ITexture; +import com.danitheskunk.skunkworks.gfx.font.IFont; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class Skunkstream extends BaseGame { + Data data; + List elements; + HashMap fonts; + HashMap textures; + HashMap nineSlices; + + public Skunkstream() { + super(new Vec2i(1920, 1080), "Skunkstream v0.0"); + data = engine.loadDataWatched("c:\\dev\\skunkstream\\test.ini"); + elements = new ArrayList<>(); + fonts = new HashMap<>(); + textures = new HashMap<>(); + nineSlices = new HashMap<>(); + fonts.put("", debugFont); + prepare(); + data.onReload(this::prepare); + } + + public static void main(String params[]) { + new Skunkstream().run(); + } + + void prepare() { + elements.clear(); + var cats = data.getCategories(); + for(var cat : cats) { + if(!cat.equals("")) { + var type = data.get(cat, "type"); + if(type.equals("label")) { + elements.add(new Label( + data.getVec2i(cat, "pos"), + data.get(cat, "text"), + fonts.get(data.get(cat, "font")), + data.getColor(cat, "color") + )); + } else if(type.equals("image")) { + var path = data.get(cat, "path"); + if(!textures.containsKey(path)) { + textures.put(path, window.loadTexture(path)); + } + elements.add(new Image( + data.getVec2i(cat, "pos"), + textures.get(path), + data.getVec2i(cat, "size"), + data.getColor(cat, "color") + )); + } else if(type.equals("9slice")) { + var path = data.get(cat, "path"); + if(!nineSlices.containsKey(path)) { + nineSlices.put(path, window.loadNineSlice(path)); + } + elements.add(new NineSlice( + data.getVec2i(cat, "pos"), + nineSlices.get(path), + data.getVec2i(cat, "size") + )); + } else if(type.equals("font")) { + if(!fonts.containsKey(cat)) { + var path = data.get(cat, "path"); + fonts.put(cat, window.loadFontTileset(path)); + } + } + } + } + } + + @Override + protected void render(IRenderContext rc) { + for(var element : elements) { + element.render(rc); + } + } +} diff --git a/test.ini b/test.ini new file mode 100644 index 0000000..109e533 --- /dev/null +++ b/test.ini @@ -0,0 +1,28 @@ +[thin_font] +type = font +path = fonts/thin-6x12.png + +[test_img] +type = image +path = test.png +pos = 50, 450 +size = 500, 100 +color = #ff0000 + +[test_label] +type = label +text = Test1234 +pos = 100x500 + +[test_label2] +type = label +text = nya! thin font test +pos = 100, 516 +color = #ff00ffff +font = thin_font + +[test_9slice] +type = 9slice +path = 9slice-2.png +pos = 200, 200 +size = 100, 50 \ No newline at end of file diff --git a/test.png b/test.png new file mode 100644 index 0000000..750c072 Binary files /dev/null and b/test.png differ