Skip to content

Commit

Permalink
Owo? Whats broken?
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Jun 10, 2024
1 parent 538abdc commit 4f2d300
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 11 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ dependencies {

modImplementation "io.wispforest:owo-lib:${project.owo_version}"
include "io.wispforest:owo-sentinel:${project.owo_version}"

modImplementation "io.wispforest:lavender:${project.lavender_version}"
// implementation "io.wispforest:endec:0.1.0-pre.8"
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ archives_base_name=trickster

# Dependencies
fabric_version=0.99.5+1.21
owo_version=0.12.8-alpha.5+1.21
owo_version=0.12.8-alpha.7+1.21
lavender_version=0.1.9-pre.1+1.21
4 changes: 4 additions & 0 deletions src/client/java/dev/enjarai/trickster/TricksterClient.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package dev.enjarai.trickster;

import dev.enjarai.trickster.screen.ModHandledScreens;
import dev.enjarai.trickster.screen.owo.GlyphComponent;
import io.wispforest.owo.ui.parsing.UIParsing;
import net.fabricmc.api.ClientModInitializer;

public class TricksterClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ModHandledScreens.register();

UIParsing.registerFactory(Trickster.id("glyph"), GlyphComponent::parse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ protected void drawGlyph(DrawContext context, SpellPart parent, float x, float y
for (var b : patternList) {
var now = getPatternDotPosition(x, y, b, patternSize);
if (last != null) {
drawGlyphLine(context, last, now, pixelSize, isDrawing);
drawGlyphLine(context, last, now, pixelSize, isDrawing, 1, 0.5f);
}
last = now;
}

if (isDrawing && last != null) {
var now = new Vector2f(mouseX, mouseY);
drawGlyphLine(context, last, now, pixelSize, true);
drawGlyphLine(context, last, now, pixelSize, true, 1, 0.5f);
}
}
}

protected void drawGlyphLine(DrawContext context, Vector2f last, Vector2f now, float pixelSize, boolean isDrawing) {
public static void drawGlyphLine(DrawContext context, Vector2f last, Vector2f now, float pixelSize, boolean isDrawing, float tone, float opacity) {
var parallelVec = new Vector2f(last.y - now.y, now.x - last.x).normalize().mul(pixelSize / 2);
var directionVec = new Vector2f(last.x - now.x, last.y - now.y).normalize().mul(pixelSize * 3);

Expand All @@ -203,10 +203,10 @@ protected void drawGlyphLine(DrawContext context, Vector2f last, Vector2f now, f
c.accept(last.x + parallelVec.x - directionVec.x, last.y + parallelVec.y - directionVec.y);
c.accept(now.x + parallelVec.x + directionVec.x, now.y + parallelVec.y + directionVec.y);
c.accept(now.x - parallelVec.x + directionVec.x, now.y - parallelVec.y + directionVec.y);
}, 0, isDrawing ? 0.5f : 1, isDrawing ? 0.5f : 1, 1, 0.5f);
}, 0, isDrawing ? 0.5f : tone, isDrawing ? 0.5f : tone, tone, opacity);
}

static Vector2f getPatternDotPosition(float x, float y, int i, float size) {
public static Vector2f getPatternDotPosition(float x, float y, int i, float size) {
float xSign = (float) (i % 3 - 1);
float ySign = (float) (i / 3 - 1);

Expand Down Expand Up @@ -242,7 +242,7 @@ static void drawTexturedQuad(DrawContext context, Identifier texture, float x1,
RenderSystem.setShaderColor(1, 1, 1, 1);
}

static void drawFlatPolygon(DrawContext context, Consumer<BiConsumer<Float, Float>> vertexProvider, float z, float r, float g, float b, float alpha) {
public static void drawFlatPolygon(DrawContext context, Consumer<BiConsumer<Float, Float>> vertexProvider, float z, float r, float g, float b, float alpha) {
Matrix4f matrix4f = context.getMatrices().peek().getPositionMatrix();
VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getGui());
vertexProvider.accept((x, y) -> vertexConsumer.vertex(matrix4f, x, y, z).color(r, g, b, alpha));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package dev.enjarai.trickster.screen.owo;

import dev.enjarai.trickster.spell.tricks.Trick;
import dev.enjarai.trickster.spell.tricks.Tricks;
import io.wispforest.owo.ui.base.BaseComponent;
import io.wispforest.owo.ui.core.OwoUIDrawContext;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.parsing.UIParsing;
import org.joml.Vector2f;
import org.w3c.dom.Element;

import java.util.List;
import java.util.stream.IntStream;

import static dev.enjarai.trickster.screen.SpellPartWidget.*;

public class GlyphComponent extends BaseComponent {
protected Trick trick;
protected List<Integer> patternList;
protected int size;

public GlyphComponent(Trick trick, int size) {
super();
this.trick = trick;
this.size = size;
this.patternList = trick.getPattern()
.entries().stream()
.flatMapToInt(e -> IntStream.of(e.p1(), e.p2()))
.distinct()
.boxed()
.toList();
}

@Override
public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {
var patternSize = size / 2;

for (int i = 0; i < 9; i++) {
var pos = getPatternDotPosition(x + patternSize + 4, y + patternSize + 4, i, patternSize);

var isLinked = patternList.contains(i);
var dotSize = 1;

drawFlatPolygon(context, c -> {
c.accept(pos.x - dotSize, pos.y - dotSize);
c.accept(pos.x - dotSize, pos.y + dotSize);
c.accept(pos.x + dotSize, pos.y + dotSize);
c.accept(pos.x + dotSize, pos.y - dotSize);
}, 0, 0, 0, 0, isLinked ? 0.9f : 0.5f);
}

for (var line : trick.getPattern().entries()) {
var now = getPatternDotPosition(x + patternSize + 4, y + patternSize + 4, line.p1(), patternSize);
var last = getPatternDotPosition(x + patternSize + 4, y + patternSize + 4, line.p2(), patternSize);
drawGlyphLine(context, last, now, 1, false, 0, 0.9f);
}
}

@Override
protected int determineHorizontalContentSize(Sizing sizing) {
return size + 8;
}

@Override
protected int determineVerticalContentSize(Sizing sizing) {
return size + 8;
}

public static GlyphComponent parse(Element element) {
UIParsing.expectAttributes(element, "trick-id");
UIParsing.expectAttributes(element, "size");

var trickId = UIParsing.parseIdentifier(element.getAttributeNode("trick-id"));
var trick = Tricks.REGISTRY.get(trickId);

if (trick == null) {
throw new IllegalArgumentException("Not a valid trick: " + trickId);
}

var size = UIParsing.parseUnsignedInt(element.getAttributeNode("size"));

return new GlyphComponent(trick, size);
}
}
6 changes: 5 additions & 1 deletion src/main/java/dev/enjarai/trickster/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import dev.enjarai.trickster.item.component.ModComponents;
import dev.enjarai.trickster.item.component.SpellComponent;
import dev.enjarai.trickster.spell.SpellPart;
import io.wispforest.lavender.book.LavenderBookItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

public class ModItems {
public static final LavenderBookItem TOME_OF_TOMFOOLERY = LavenderBookItem.registerForBook(
Trickster.id("tome_of_tomfoolery"), new Item.Settings().maxCount(1));
public static final ScrollAndQuillItem SCROLL_AND_QUILL = register("scroll_and_quill",
new ScrollAndQuillItem(new Item.Settings().component(ModComponents.SPELL, new SpellComponent(new SpellPart()))));
new ScrollAndQuillItem(new Item.Settings().maxCount(16)
.component(ModComponents.SPELL, new SpellComponent(new SpellPart()))));

private static <T extends Item> T register(String name, T item) {
return Registry.register(Registries.ITEM, Trickster.id(name), item);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.enjarai.trickster.screen;

import com.mojang.serialization.JsonOps;
import dev.enjarai.trickster.Trickster;
import dev.enjarai.trickster.item.component.ModComponents;
import dev.enjarai.trickster.item.component.SpellComponent;
import dev.enjarai.trickster.spell.SpellPart;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/enjarai/trickster/spell/Pattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Pattern of(int... pattern) {
return from(Stream.of(ArrayUtils.toObject(pattern)).map(Integer::byteValue).toList());
}

record PatternEntry(byte p1, byte p2) implements Comparable<PatternEntry> {
public record PatternEntry(byte p1, byte p2) implements Comparable<PatternEntry> {
public static final Codec<PatternEntry> CODEC = Codec.BYTE.listOf(2, 2)
.xmap(list -> new PatternEntry(list.getFirst(), list.getLast()), entry -> List.of(entry.p1, entry.p2));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"texture": "trickster:textures/gui/white_book.png"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
```json
{
"title": "Arithmetic",
"icon": "minecraft:copper_bulb"
}
```

The following patterns regard basic arithmetic and simple mathematical operations.


Many base arithmetical operations, though not all, will work on both single numbers and vectors.

;;;;;

<|glyph@trickster:templates|trick-id=trickster:add,title=Summation|>

number... -> number |

vec... -> vec

---

Adds up an arbitrary sequence of numbers into a single value.
Works with vectors.

;;;;;

<|glyph@trickster:templates|trick-id=trickster:subtract,title=Subtraction|>

number... -> number |

vec... -> vec

---

Sequentially subtracts an arbitrary sequence of numbers into a single value.
Works with vectors.

;;;;;

<|glyph@trickster:templates|trick-id=trickster:multiply,title=Multiplication|>

(number | vec)... -> (number | vec)

---

Multiplies many numbers into a single value.
A number and a vector combined will result in a vector.

;;;;;

<|glyph@trickster:templates|trick-id=trickster:divide,title=Subtraction|>

number... -> number |

vec... -> vec

---

Sequentially subtracts an arbitrary sequence of numbers into a single value.
Works with vectors.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "trickster:item/tome_of_tomfoolery"
}
}
38 changes: 38 additions & 0 deletions src/main/resources/assets/trickster/owo_ui/templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<owo-ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/wisp-forest/owo-lib/1.20/owo-ui.xsd">
<templates>
<template name="glyph">
<flow-layout direction="vertical">
<children>
<label>
<text>{{title}}</text>
</label>
<label>
<text>{{trick-id}}</text>
</label>
<!-- <label>-->
<!-- <text>{{title}}</text>-->
<!-- <color>dark-gray</color>-->

<!-- <horizontal-text-alignment>center</horizontal-text-alignment>-->

<!-- <margins>-->
<!-- <top>2</top>-->
<!-- <bottom>2</bottom>-->
<!-- </margins>-->
<!-- <sizing>-->
<!-- <horizontal method="fill">100</horizontal>-->
<!-- </sizing>-->
<!-- </label>-->

<!-- <trickster.glyph trick-id="{{trick-id}}" size="50">-->
<!-- </trickster.glyph>-->
</children>
<horizontal-alignment>center</horizontal-alignment>
<sizing>
<horizontal method="fill">100</horizontal>
</sizing>
</flow-layout>
</template>
</templates>
</owo-ui>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f2d300

Please sign in to comment.