Skip to content

Commit

Permalink
Message on conflicting asset names, needs colour.
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Sep 14, 2023
1 parent 2fc6587 commit 7501e64
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 65 deletions.
48 changes: 0 additions & 48 deletions demos/pirate/assets/shaders/frag.frag

This file was deleted.

3 changes: 0 additions & 3 deletions demos/pirate/assets/shaders/vert.vert

This file was deleted.

24 changes: 10 additions & 14 deletions demos/pirate/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ Global / onChangedBuildSource := ReloadOnSourceChanges

val scala3Version = "3.3.0"

lazy val pirateOptions: IndigoOptions =
IndigoOptions.defaults
.withTitle("The Cursed Pirate")
.withWindowWidth(1280)
.withWindowHeight(720)
.withBackgroundColor("black")

lazy val pirate =
(project in file("."))
.enablePlugins(
Expand All @@ -27,22 +34,11 @@ lazy val pirate =
Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }
)
.settings( // Indigo specific settings
indigoOptions :=
IndigoOptions.defaults
.withTitle("The Cursed Pirate")
.withWindowWidth(1280)
.withWindowHeight(720)
.withBackgroundColor("black")
.excludeAssetPaths { case p: String if p.startsWith("shaders") => true },
indigoOptions := pirateOptions,
indigoGenerators :=
IndigoGenerators
.sbt((Compile / sourceManaged).value, "some.pkg")
.embedGLSLShaders(
"MyShader",
"assets/shaders/vert.vert",
"assets/shaders/frag.frag",
false
),
.sbt((Compile / sourceManaged).value, "pirate.generated")
.listAssets("GeneratedAssets", pirateOptions.assets),
libraryDependencies ++= Seq(
"io.indigoengine" %%% "indigo-json-circe" % IndigoVersion.getVersion, // Needed for Aseprite & Tiled support
"io.indigoengine" %%% "indigo" % IndigoVersion.getVersion, // Important! :-)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package indigoplugin.generators

import indigoplugin.IndigoAssets
import scala.annotation.tailrec

object AssetListing {

Expand Down Expand Up @@ -67,6 +68,38 @@ object AssetListing {
renderFolderContents("", children, indent, toSafeName)
}

def errorOnDuplicates(files: List[PathTree.File], toSafeName: (String, String) => String): Unit = {
@tailrec
def rec(remaining: List[PathTree.File], acc: List[(String, PathTree.File, PathTree.File)]): List[String] =
remaining match {
case Nil =>
acc.map { case (n, a, b) =>
s"""'$n' is the safe name of both '${a.fullName}' and '${b.fullName}'."""
}

case e :: es =>
val errors = es
.filter(n => toSafeName(n.name, n.extension) == toSafeName(e.name, e.extension))
.map(n => (toSafeName(e.name, e.extension), e, n))
rec(es, acc ++ errors)
}

val errors = rec(files, Nil)

if (errors.nonEmpty) {
val msg =
s"""
|**Generated asset names collision!**
|You have one or more conflicting asset names. Please change these names, or move them to separate sub-folders within your assets directory."
|The following assets would have the same names in your generated asset listings code:
|
|${errors.mkString("\n")}
|""".stripMargin

println(msg)
} else ()
}

def renderFolderContents(
folderName: String,
children: List[PathTree],
Expand All @@ -79,6 +112,8 @@ object AssetListing {
val safeFolderName = toSafeName(folderName, "")
val files: List[PathTree.File] = children.collect { case f: PathTree.File => f }

errorOnDuplicates(files, toSafeName)

val renderedFiles: List[(String, String)] =
files
.map {
Expand Down

0 comments on commit 7501e64

Please sign in to comment.