Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Sep 26, 2023
1 parent d26308e commit 426377c
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 38 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "sgine"
ThisBuild / organization := "org.sgine"
ThisBuild / version := "2.0.0b5-SNAPSHOT"
ThisBuild / version := "2.0.0b5-SNAPSHOT2"

val scala213 = "2.13.11"

Expand Down Expand Up @@ -37,7 +37,7 @@ val reactifyVersion: String = "4.1.0"
val fabricVersion: String = "1.12.6"
val scribeVersion: String = "3.12.2"
val shapedrawerVersion: String = "2.6.0"
val media4sVersion: String = "1.0.20"
val media4sVersion: String = "1.0.21"

val scalaXMLVersion = "2.0.0-M2"
val androidVersion = "4.1.1.4"
Expand Down
7 changes: 3 additions & 4 deletions core/src/main/scala/org/sgine/audio/Audio.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ object Audio extends UpdateSupport {
def info(file: FileHandle): AudioInfo = _info().get(file.path()) match {
case Some(info) => info
case None =>
val tmp = File.createTempFile("audio-info", file.path())
val bytes = file.readBytes()
Files.write(tmp.toPath, bytes)
val f = new File(resourcesDirectory.get, file.path())
assert(f.isFile, s"Unable to find ${file.path()} in ${resourcesDirectory.get.getCanonicalPath}")

val mediaInfo = VideoUtil.info(tmp)
val mediaInfo = VideoUtil.info(f)
val info = AudioInfo(mediaInfo.duration)
synchronized {
_info @= _info() + (file.path() -> info)
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/org/sgine/drawable/Drawer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ case class Drawer(shapeDrawer: ShapeDrawer) {
innerColor: Color,
outerColor: Color): Unit = {
preDraw()

shapeDrawer.sector(
x.cx,
y.cy,
Expand Down
27 changes: 19 additions & 8 deletions core/src/main/scala/org/sgine/drawable/TextureManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ abstract class TextureManager(fileName: Option[String],
val outputPath = new File(this.path)
outputPath.mkdirs()

val inputFiles = inputDirectory.listFiles().toList
def recurseFiles(dir: File, prefix: String): List[(File, String)] = {
val files = dir.listFiles().toList
files.flatMap { file =>
if (file.isDirectory) {
recurseFiles(file, s"$prefix${file.getName.capitalize}")
} else {
List((file, s"$prefix${file.getName.capitalize}"))
}
}
}
val inputFiles = recurseFiles(inputDirectory, "")
val atlasTextureCount = atlas.flatMap(_._2).size
val newestFileTime = inputFiles.map(_.lastModified()).max
val newestFileTime = inputFiles.map(_._1.lastModified()).max
val shouldRegen = if (atlasTextureCount != inputFiles.length) {
scribe.info(s"Atlas texture count ($atlasTextureCount) is not the same as the input file count (${inputFiles.length}). Regenerating...")
true
Expand All @@ -94,12 +104,13 @@ abstract class TextureManager(fileName: Option[String],
val packageName = getClass.getPackage.getName
val className = getClass.getSimpleName.replace("$", "")
val IndexedRegex = """(.+)_(\d{1,2})""".r
val textureMappings = inputFiles.groupBy { file =>
val fileName = file.getName
fileName.substring(0, fileName.indexOf('.')) match {
case IndexedRegex(name, _) => name
case s => s
}

val textureMappings = inputFiles.groupBy {
case (_, fileName) =>
fileName.substring(0, fileName.indexOf('.')) match {
case IndexedRegex(name, _) => name
case s => s
}
}
val textureNames = textureMappings.keys.toList.sorted
val textureEntries = textureNames.map { textureName =>
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/org/sgine/font/FontManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ trait FontManager {

protected def create[Return](path: String, allowMarkup: Boolean = true)
(f: Generator => Return): Return = {
FreeTypeFontGenerator.setMaxTextureSize(4096)
val ftfg = new FreeTypeFontGenerator(Gdx.files.internal(path))
try {
val generator = (size: Int) => {
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/org/sgine/update/Updates.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.util.Try
class Updates extends Channel[Double] {
def every(delay: Double,
stopIn: Double = Int.MaxValue.toDouble)
(f: => Unit): Unit = {
(f: => Unit): Reaction[Double] = {
var total = 0.0
var elapsed = 0.0
var reaction: Reaction[Double] = null
Expand All @@ -23,6 +23,7 @@ class Updates extends Channel[Double] {
reactions -= reaction
}
}
reaction
}

def in(delay: Double)(f: => Unit): Unit = every(delay, stopIn = delay)(f)
Expand Down
27 changes: 18 additions & 9 deletions core/src/main/scala/org/sgine/util/CreateTextureAtlas.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@ object CreateTextureAtlas {
val packer = new PixmapPacker(
pageWidth, pageHeight, pageFormat, padding, duplicateBorder, stripWhitespaceX, stripWhitespaceY, packStrategy
)
val directory = new File(inputPath)
val files = directory.listFiles().toList.sortBy(_.getName)
val fileCount = files.size
files.zipWithIndex.foreach {
case (file, index) =>
val name = file.getName.substring(0, file.getName.indexOf('.'))
val image = new Pixmap(Gdx.files.absolute(file.getCanonicalPath))
scribe.info(s"Packing $name (${index + 1} of $fileCount)...")
packer.pack(name, image)

def processDirectory(directory: File, prefix: String): Unit = {
val files = directory.listFiles().toList.sortBy(_.getName)
val fileCount = files.size
files.zipWithIndex.foreach {
case (file, index) =>
if (file.isDirectory) {
processDirectory(file, s"$prefix${file.getName.capitalize}")
} else {
val name = file.getName.substring(0, file.getName.indexOf('.')).capitalize
val fullName = s"$prefix$name"
val image = new Pixmap(Gdx.files.absolute(file.getCanonicalPath))
scribe.info(s"Packing $fullName (${index + 1} of $fileCount)...")
packer.pack(fullName, image)
}
}
}
processDirectory(new File(inputPath), "")

val parameters = new PixmapPackerIO.SaveParameters
parameters.format = PixmapPackerIO.ImageFormat.PNG
parameters.magFilter = TextureFilter.Nearest
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/scala/examples/Fonts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ object Fonts extends FontManager {
object OpenSans {
object Regular {
lazy val (small, normal, large, extraLarge) = create("OpenSans-Regular.ttf") { generator =>
(generator(48), generator(64), generator(100), generator(150))
(generator(48), generator(64), generator(100), generator(250))
}
}
}
object Pacifico {
lazy val normal: BitmapFont = create("Pacifico.ttf") { generator =>
generator(100)
lazy val (normal, large) = create("Pacifico.ttf") { generator =>
(generator(100), generator(200))
}
}
}
29 changes: 19 additions & 10 deletions core/src/test/scala/examples/LabelExample.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package examples

import org.sgine.Color
import org.sgine.component.{Component, PointerSupport, Label}
import org.sgine.component.{Component, Container, Label, PointerSupport}
import reactify._

object LabelExample extends Example {
override protected lazy val component: Component = new Label("Hello, [#00ff00ff]World![]\n\nTesting, this is some [#00ffffff]really long text[] that should wrap multiple lines!") with PointerSupport {
font @= Fonts.Pacifico.normal
center @= screen.center
middle @= screen.middle
wrap @= true
width @= 1000.0
override protected lazy val component: Component = Container(
new Label("Hello, [#00ff00ff]World![]\n\nTesting, this is some [#00ffffff]really long text[] that should wrap multiple lines!") with PointerSupport {
font @= Fonts.Pacifico.normal
center @= screen.center
middle @= screen.middle
wrap @= true
width @= 1000.0

color := (if (pointer.isOver) Color.Red else Color.White)
color := (if (pointer.isOver) Color.Red else Color.White)

override def toString: String = "text"
}
override def toString: String = "text"
},
new Label("Giant Text Here") {
font @= Fonts.Pacifico.large
center := screen.center
top @= 10.0

color @= Color.White
}
)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.4
sbt.version=1.9.6

0 comments on commit 426377c

Please sign in to comment.