Skip to content

Commit

Permalink
adding in the ability to publish to github packages
Browse files Browse the repository at this point in the history
  • Loading branch information
patbeagan1 committed Jan 9, 2023
1 parent 3d0a336 commit fa9125c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 93 deletions.
13 changes: 8 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("org.jetbrains.kotlin.jvm") version "1.6.10"
id("org.jetbrains.kotlin.jvm") version "1.7.22"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
}
Expand All @@ -11,14 +11,17 @@ repositories {
mavenCentral()
}

version = "0.8.0"
group = "dev.patbeagan"

childProjects
.onEach { println(it) }
.filter { it.key in listOf("app", "lib", "server") }
.forEach { entry ->
entry.value.run {
group = "dev.patbeagan"
version = "0.7.0"
afterEvaluate {
entry.value.let { project ->
project.group = group
project.version = version
project.afterEvaluate {
tasks {
named<ShadowJar>("shadowJar") {
minimize()
Expand Down
21 changes: 20 additions & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

plugins {
id("java-library")
id("org.jetbrains.kotlin.jvm")
id("com.github.johnrengelman.shadow")
id("org.jlleitschuh.gradle.ktlint")
`maven-publish`
}

repositories {
Expand All @@ -18,3 +18,22 @@ dependencies {
testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlin:kotlin-reflect:1.3.72")
}

publishing {
repositories {
maven {
name = "ConsoleVision"
url = uri("https://maven.pkg.github.com/patbeagan1/ConsoleVision")
credentials {
username = System.getenv("GITHUB_ACTOR_CONSOLE_VISION")
password = System.getenv("GITHUB_TOKEN_CONSOLE_VISION")
}
}
}
publications {
register<MavenPublication>("gpr") {
from(components["java"])
this.artifactId = "console-vision"
}
}
}
71 changes: 0 additions & 71 deletions lib/src/main/kotlin/dev/patbeagan/consolevision/ImagePrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,74 +102,3 @@ class ImagePrinter(
}
}
}

//
//class ImagePrinter {
// enum class CompressionStyle {
// UP_DOWN, DOTS
// }
//
// fun printImageCompressed(read: BufferedImage, compressionStyle: CompressionStyle = UP_DOWN) {
// (read.minY until read.height).chunked(2).forEach { y ->
// (read.minX until read.width).forEach { x ->
// val (a, r, g, b) = read.getRGB(x, y[0]).colorIntToARGB()
// val (a1, r1, g1, b1) = read.getRGB(x, y[1]).colorIntToARGB()
// when (compressionStyle) {
// UP_DOWN -> "▄"
// DOTS -> "▓"
// }.style(
// colorBackground = if (a == 0) Colors.Custom(g = 255) else Colors.Custom(r, g, b),
// colorForeground = if (a1 == 0) Colors.Custom(g = 255) else Colors.Custom(r1, g1, b1)
// ).also { print(it) }
// }
// println()
// }
// }
//
// fun printImageReducedPalette(read: BufferedImage) {
// (read.minY until read.height).chunked(2).forEach { y ->
// (read.minX until read.width).forEach { x ->
// val a = read.getRGB(x, y[0]).colorIntToARGB().argbToColorInt(false)
// val b = read.getRGB(x, y[1]).colorIntToARGB().argbToColorInt(false)
// "▄".style(
// colorBackground = Color256.reduceColor16(a).let { Colors.CustomPreset(it ) },
// colorForeground = Color256.reduceColor16(b).let { Colors.CustomPreset(it ) }
// ).also { print(it) }
// }
// println()
// }
// }
//
// fun printImage(read: BufferedImage) {
// (read.minY until read.height).forEach { y ->
// (read.minX until read.width).forEach { x ->
// val (a, r, g, b) = read.getRGB(x, y).colorIntToARGB()
// " ".style(
// colorBackground = if (a == 0) {
// Colors.Custom(g = 255)
// } else {
// Colors.Custom(r, g, b)
// }
// ).also { print(it) }
// }
// println()
// }
// }
//}
//
//fun Image.convertToBufferedImage(): BufferedImage? {
// if (this is BufferedImage) {
// return this
// }
//
// // Create a buffered image with transparency
// val bi = BufferedImage(
// getWidth(null), getHeight(null),
// BufferedImage.TYPE_INT_ARGB
// )
// val graphics2D = bi.createGraphics()
// graphics2D.drawImage(this, 0, 0, null)
// graphics2D.dispose()
// return bi
//}
//
87 changes: 71 additions & 16 deletions lib/src/main/kotlin/dev/patbeagan/consolevision/types/List2D.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
package dev.patbeagan.consolevision.types

/**
* This is a representation of a 2D grid.
*
* Common operations on 2D arrays can be done within this class.
*/
@JvmInline
value class List2D<T>(private val value: MutableList<MutableList<T>>) : Iterable<T> {

val height get() = value.size
val width get() = value.firstOrNull()?.size ?: 0

value class List2D<T> private constructor(private val value: MutableList<MutableList<T>>) :
Iterable<T> {

/**
* The height of the 2d list. This is the number of rows that it contains.
*/
val height: Int get() = value.size

/**
* The width of the 2d list. This is the number of columns that it contains.
*/
val width: Int get() = value.firstOrNull()?.size ?: 0

/**
* Gets the value at a certain X,Y coordinate.
*/
fun at(x: Int, y: Int): T = value[y][x]

/**
* Sets the value at a certain X,Y coordinate.
*/
fun assign(x: Int, y: Int, item: T) {
value[y][x] = item
}
Expand All @@ -15,19 +35,31 @@ value class List2D<T>(private val value: MutableList<MutableList<T>>) : Iterable
this@List2D.traverseInternal(value, {}) { _, _, t -> yield(t) }
}

/**
* Traverses the 2D array, and mutates each cell.
* This is more performant than using [map].
*/
fun traverseMutate(
onElement: (x: Int, y: Int, each: T) -> T,
): Unit = value.forEachIndexed { y, row ->
row.forEachIndexed { x, t -> value[y][x] = onElement(x, y, t) }
}

/**
* Analogous to [List.mapIndexed]
*
* Returns a [List2D] containing the results
* of applying the given transform function to each element
* and its index in the original collection.
*/
fun <R> traverseMapIndexed(
onElement: (x: Int, y: Int, T) -> R,
): List2D<R> = from(
value.mapIndexed { y, r ->
r.mapIndexed { x, it -> onElement(x, y, it) }
})
): List2D<R> = from(value.mapIndexed { y, r -> r.mapIndexed { x, it -> onElement(x, y, it) } })


/**
* Puts a given value into all the cells within a given list of coordinates.
*/
fun traverseAssign(list: List<CompressedPoint>, t: T) {
list.forEach {
if (it.y in this.value.indices && it.x in this.value[0].indices) {
Expand All @@ -36,16 +68,31 @@ value class List2D<T>(private val value: MutableList<MutableList<T>>) : Iterable
}
}

/**
* Analogous to [List.map]
*
* Returns a [List2D] containing the results
* of applying the given transform function to each element
* in the original collection.
*/
fun <R> traverseMap(
onElement: (T) -> R,
): List2D<R> = traverseMapIndexed { _, _, t -> onElement(t) }

/**
* Analogous to [List.forEach]
*
* Traverses the [List2D], by visiting each cell.
* Includes 2 callable blocks, for visiting an element,
* and for when the current row is completed.
*/
fun traverse(
onRowEnd: () -> Unit = {},
onElement: (x: Int, y: Int, T) -> Unit,
): Unit = traverseInternal(value, onRowEnd, onElement)

private inline fun traverseInternal(
// needed so that we can access the value field, in traverse
list: MutableList<MutableList<T>>,
onRowEnd: () -> Unit = {},
onElement: (x: Int, y: Int, T) -> Unit,
Expand All @@ -54,16 +101,27 @@ value class List2D<T>(private val value: MutableList<MutableList<T>>) : Iterable
onRowEnd()
}

/**
* Verifies that a given point is contained in the [List2D]
*/
fun isValidCoordinate(c: CompressedPoint): Boolean =
value.isNotEmpty() &&
value.all { it.size == value[0].size } &&
c.y in 0..value.size &&
c.x in 0..value[0].size

/**
* A debug method that prints all of the values that are currently in the [List2D]
*/
fun printAll(delimiter: String = "\t") {
traverse({ println() }) { _, _, t -> print("$t$delimiter") }
}

/**
* Merges two [List2D] together.
*
* This is analogous to [List.zip]
*/
inline fun <reified S, reified R> mergeWith(
other: List2D<S>,
default: R,
Expand All @@ -76,14 +134,11 @@ value class List2D<T>(private val value: MutableList<MutableList<T>>) : Iterable
}
}

fun flatten(): List<T> {
val ret = mutableListOf<T>()
iterator().forEach { ret.add(it) }
return ret
}

companion object {
fun <T> from(value: List<List<T>>) =
/**
* Creates a [List2D] from a List of Lists.
*/
fun <T> from(value: List<List<T>>): List2D<T> =
List2D(value.map { it.toMutableList() }.toMutableList())
}
}
Expand Down

0 comments on commit fa9125c

Please sign in to comment.