Skip to content

Commit

Permalink
SPIRAL v0.0.1 - Very indev, but here we go.
Browse files Browse the repository at this point in the history
* Added the MANIFEST file
* Changed SpiralFormat#getExtension to return a String, rather than an Optional String
* Changed SpiralActions to reflect that change
* Added String#getExtension
* Added a series of extraction and conversion commands to Lagann.kt
  • Loading branch information
UnderMybrella committed Mar 29, 2017
1 parent 7684e72 commit dc8b1c6
Show file tree
Hide file tree
Showing 8 changed files with 483 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ nonfunctional/
out/
test
.idea/
mods/
mods/
/bustups/
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# Spiral
Spiral is a Danganronpa Modding Framework written in Kotlin, which is currently undergoing a major rewrite. Watch this space for any updates which may or may not happen, but stay tuned!

At the moment the only way you'll be able to use this is by actually coding an extension, so trust me; it's not usable.
# Usage
Right now, the SPIRAL indev release is a **command line only program**. That means, you need to open it using either Command Prompt, or Terminal, depending on your operating system.

Open your Command Prompt or Terminal, and type in "java -jar ", and then drag in the JAR file downloaded from the Releases page. This will either start up SPIRAL or inform you that you need to install Java.

Currently, the feature set of SPIRAL is fairly limited - supporting extraction and conversion only. A full list of commands is available in the program, however for convenience a simple list is provided here
* help
* find
* registered
* convert
* operate
* exit

If you discover a bug, please report it!

# Dependencies
https://github.com/UnderMybrella/Visi
Expand Down
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: org.abimon.spiral.headless.LagannKt

11 changes: 6 additions & 5 deletions src/org/abimon/spiral/core/SpiralActions.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.abimon.spiral.core

import org.abimon.visi.io.*
import java.io.*
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
import java.util.*
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import java.util.zip.ZipInputStream
import java.util.zip.ZipOutputStream

Expand Down Expand Up @@ -66,16 +67,16 @@ fun Pak.convertToZip(name: String, outputStream: OutputStream) {
val format = possibleFormat.get()
when(format) {
is TGAFormat -> {
zipOut.putNextEntry(ZipEntry(it.name + if(SpiralFormats.PNG.getExtension().isPresent) ".${SpiralFormats.PNG.getExtension().get()}" else ""))
zipOut.putNextEntry(ZipEntry("${it.name}.${SpiralFormats.PNG.getExtension()}"))
format.convert(SpiralFormats.PNG, it, zipOut)
}
is PAKFormat -> {
zipOut.putNextEntry(ZipEntry(it.name + if(SpiralFormats.ZIP.getExtension().isPresent) ".${SpiralFormats.ZIP.getExtension().get()}" else ""))
zipOut.putNextEntry(ZipEntry("${it.name}.${SpiralFormats.ZIP.getExtension()}"))
format.convert(SpiralFormats.ZIP, it, zipOut)
}
is WADFormat -> println("Oh no. $name#${it.name} is a WAD file. Panic. Now.")
else -> {
zipOut.putNextEntry(ZipEntry(it.name + if(format.getExtension().isPresent) ".${format.getExtension().get()}" else ""))
zipOut.putNextEntry(ZipEntry("${it.name}.${format.getExtension()}"))
it.getInputStream().writeTo(zipOut)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/org/abimon/spiral/core/SpiralFormats.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import javax.imageio.ImageIO

interface SpiralFormat {
fun getName(): String
fun getExtension(): Optional<String> = getName().toLowerCase().asOptional()
fun getExtension(): String = getName().toLowerCase()
fun isFormat(source: DataSource): Boolean
fun canConvert(format: SpiralFormat): Boolean
/**
Expand Down Expand Up @@ -160,7 +160,7 @@ class PNGFormat : SpiralFormat {
}
}
class JPEGFormat : SpiralFormat {
override fun getName(): String = "JPEG"
override fun getName(): String = "JPG"

override fun isFormat(source: DataSource): Boolean =
source.getInputStream().use { ImageIO.getImageReaders(ImageIO.createImageInputStream(it))
Expand Down Expand Up @@ -205,7 +205,7 @@ object SpiralFormats {
val formats = arrayOf(WAD, PAK, TGA, ZIP, PNG, JPG)
val drWadFormats = arrayOf(WAD, PAK, TGA)

fun formatForExtension(extension: String): Optional<SpiralFormat> = formats.findOrEmpty { (it.getExtension().isPresent) and (it.getExtension().get() == extension) }
fun formatForExtension(extension: String): Optional<SpiralFormat> = formats.findOrEmpty { (it.getExtension() == extension) }
fun formatForData(dataSource: DataSource, selectiveFormats: Array<SpiralFormat> = formats): Optional<SpiralFormat> = selectiveFormats.findOrEmpty { it.isFormat(dataSource) }
fun formatForName(name: String): Optional<SpiralFormat> = formats.findOrEmpty { it.getName().equals(name, true) }

Expand Down
4 changes: 2 additions & 2 deletions src/org/abimon/spiral/core/SpiralObjects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ class Pak(val dataSource: DataSource) {

for (i in 0 until numFiles) {
offsets[i] = pak.readNumber(4, true)
if (offsets[i] <= 0)
throw IllegalArgumentException("${dataSource.getLocation()} is either not a valid PAK file, or is corrupt (${offsets[i]} <= 0)")
if (offsets[i] < 0)
throw IllegalArgumentException("${dataSource.getLocation()} is either not a valid PAK file, or is corrupt (${offsets[i]} < 0)")
else if (offsets[i] >= dataSource.getDataSize())
throw IllegalArgumentException("${dataSource.getLocation()} is either not a valid PAK file, or is corrupt (${offsets[i]} >= ${dataSource.getDataSize()})")
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/abimon/spiral/core/SpiralPowers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ fun String.getChild(): String {
return if(this.lastIndexOf('/') == -1) this else this.substring(this.lastIndexOf('/') + 1, length)
}

fun String.getExtension(): String {
return if(this.lastIndexOf('.') == -1) this else this.substring(this.lastIndexOf('.') + 1, length)
}

fun <T> T.asOptional(): Optional<T> = Optional.of(this)

inline fun <T> Array<out T>.findOrEmpty(predicate: (T) -> Boolean): Optional<T> {
Expand Down
Loading

0 comments on commit dc8b1c6

Please sign in to comment.