Compare commits

..

No commits in common. "8a3be763f11d58acbcbb985a0651207d88380971" and "aa9181cfeaf68d4cde0c42dff561f92805247ede" have entirely different histories.

7 changed files with 9 additions and 116 deletions

View File

@ -2,9 +2,9 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
kotlin("jvm") version "1.3.50" kotlin("jvm") version "1.3.40"
idea idea
id("fabric-loom") version "0.2.5-SNAPSHOT" id("fabric-loom") version "0.2.3-SNAPSHOT"
id("com.github.johnrengelman.shadow") version "4.0.4" id("com.github.johnrengelman.shadow") version "4.0.4"
} }
@ -22,9 +22,9 @@ version = "0.1.0"
val minecraftVersion = "1.14.4" val minecraftVersion = "1.14.4"
val yarnMappings = "1.14.4+build.9" val yarnMappings = "1.14.4+build.9"
val loaderVersion = "0.6.3+build.167" val loaderVersion = "0.4.8+build.159"
val fabricVersion = "0.4.0+build.240-1.14" val fabricVersion = "0.3.1+build.208"
val fabricKotlinVersion = "1.3.50+build.3" val fabricKotlinVersion = "1.3.40+build.1"
val junitVersion = "5.4.0" val junitVersion = "5.4.0"
minecraft { minecraft {
@ -34,7 +34,6 @@ repositories {
maven(url = "http://maven.fabricmc.net/") { maven(url = "http://maven.fabricmc.net/") {
name = "Fabric" name = "Fabric"
} }
maven(url = "https://kotlin.bintray.com/kotlinx")
jcenter() jcenter()
mavenLocal() mavenLocal()
} }
@ -46,11 +45,11 @@ dependencies {
mappings(group = "net.fabricmc", name = "yarn", version = yarnMappings) mappings(group = "net.fabricmc", name = "yarn", version = yarnMappings)
modImplementation(group = "net.fabricmc", name = "fabric-loader", version = loaderVersion) modCompile(group = "net.fabricmc", name = "fabric-loader", version = loaderVersion)
modImplementation(group = "net.fabricmc.fabric-api", name = "fabric-api", version = fabricVersion) modCompile(group = "net.fabricmc.fabric-api", name = "fabric-api", version = fabricVersion)
modImplementation(group = "net.fabricmc", name = "fabric-language-kotlin", version = fabricKotlinVersion) modCompile(group = "net.fabricmc", name = "fabric-language-kotlin", version = fabricKotlinVersion)
// compileOnly(group = "net.fabricmc", name = "fabric-language-kotlin", version = fabricKotlinVersion) compileOnly(group = "net.fabricmc", name = "fabric-language-kotlin", version = fabricKotlinVersion)
// compileOnly(group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version = "1.3.21") // compileOnly(group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version = "1.3.21")
// compileOnly(group = "org.jetbrains.kotlin", name = "kotlin-reflect", version = "1.3.21") // compileOnly(group = "org.jetbrains.kotlin", name = "kotlin-reflect", version = "1.3.21")

View File

@ -37,11 +37,8 @@ open class CacaoScreen: Screen(LiteralText("CacaoScreen")) {
*/ */
fun <T: Window> addWindow(window: T, index: Int = _windows.size): T { fun <T: Window> addWindow(window: T, index: Int = _windows.size): T {
_windows.add(index, window) _windows.add(index, window)
window.screen = this window.screen = this
window.wasAdded()
window.resize(width, height) window.resize(width, height)
return window return window
} }

View File

@ -79,9 +79,7 @@ class Window(
init { init {
createInternalConstraints() createInternalConstraints()
}
fun wasAdded() {
viewController.window = this viewController.window = this
viewController.loadView() viewController.loadView()

View File

@ -1,49 +0,0 @@
package net.shadowfacts.cacao.geometry
import java.lang.RuntimeException
import kotlin.math.pow
/**
* Helper class that represents a cubic bezier curve.
*
* @author shadowfacts
*/
data class BezierCurve(private val points: Array<Point>) {
init {
if (points.size != 4) {
throw RuntimeException("Cubic bezier curve must have exactly four points")
}
}
fun point(time: Double): Point {
val x = coordinate(time, Axis.HORIZONTAL)
val y = coordinate(time, Axis.VERTICAL)
return Point(x, y)
}
private fun coordinate(t: Double, axis: Axis): Double {
// B(t)=(1-t)^3*p0+3(1-t)^2*t*p1+3(1-t)*t^2*p2+t^3*p3
val p0 = points[0][axis]
val p1 = points[1][axis]
val p2 = points[2][axis]
val p3 = points[3][axis]
return ((1 - t).pow(3) * p0) + (3 * (1 - t).pow(2) * t * p1) + (3 * (1 - t) * t.pow(2) * p2) + (t.pow(3) * p3)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as BezierCurve
if (!points.contentEquals(other.points)) return false
return true
}
override fun hashCode(): Int {
return points.contentHashCode()
}
}

View File

@ -21,11 +21,4 @@ data class Point(val x: Double, val y: Double) {
return Point(x - other.x, y - other.y) return Point(x - other.x, y - other.y)
} }
operator fun get(axis: Axis): Double {
return when (axis) {
Axis.HORIZONTAL -> x
Axis.VERTICAL -> y
}
}
} }

View File

@ -9,7 +9,6 @@ import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormats import net.minecraft.client.render.VertexFormats
import net.minecraft.client.sound.PositionedSoundInstance import net.minecraft.client.sound.PositionedSoundInstance
import net.minecraft.sound.SoundEvent import net.minecraft.sound.SoundEvent
import net.shadowfacts.cacao.geometry.BezierCurve
import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.geometry.Point
import net.shadowfacts.cacao.geometry.Rect import net.shadowfacts.cacao.geometry.Rect
import net.shadowfacts.cacao.util.texture.Texture import net.shadowfacts.cacao.util.texture.Texture
@ -109,14 +108,6 @@ object RenderHelper {
GlStateManager.translated(x, y, z) GlStateManager.translated(x, y, z)
} }
/**
* @see org.lwjgl.opengl.GL11.glScaled
*/
fun scale(x: Double, y: Double, z: Double = 1.0) {
if (disabled) return
GlStateManager.scaled(x, y, z)
}
/** /**
* @see org.lwjgl.opengl.GL11.glColor4f * @see org.lwjgl.opengl.GL11.glColor4f
*/ */

View File

@ -1,36 +0,0 @@
package net.shadowfacts.cacao.view
import com.mojang.blaze3d.platform.GlStateManager
import net.shadowfacts.cacao.geometry.BezierCurve
import net.shadowfacts.cacao.geometry.Point
import net.shadowfacts.cacao.util.Color
import net.shadowfacts.cacao.util.RenderHelper
/**
* @author shadowfacts
*/
class BezierCurveView(val curve: BezierCurve): View() {
private val points by lazy {
val step = 0.05
var t = 0.0
val points = mutableListOf<Point>()
while (t <= 1) {
points.add(curve.point(t))
t += step
}
points
}
var lineWidth = 3f
var lineColor = Color.BLACK
override fun drawContent(mouse: Point, delta: Float) {
RenderHelper.scale(bounds.width, bounds.height)
for ((index, point) in points.withIndex()) {
val next = points.getOrNull(index + 1) ?: break
RenderHelper.drawLine(point, next, zIndex, lineWidth, lineColor)
}
}
}