Skip to content

Commit

Permalink
Add generated font to sandbox scene
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Apr 24, 2024
1 parent 878e501 commit f45f436
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
20 changes: 19 additions & 1 deletion indigo/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,25 @@ lazy val sandbox =
IndigoOptions.defaults
.withTitle("Sandbox")
.withBackgroundColor("black")
.withAssetDirectory("sandbox/assets/")
.withAssetDirectory("sandbox/assets/"),
Compile / sourceGenerators += Def.task {
IndigoGenerators("example")
.embedFont(
"TestFont",
os.pwd / "sandbox" / "assets" / "fonts" / "pixelated.ttf",
indigoplugin.generators
.FontOptions(
"test font",
32,
indigoplugin.generators.CharSet.fromUniqueString("The quick brown fox\njumps over the\nlazy dog.")
)
.withColor(indigoplugin.generators.RGB.White)
.withMaxCharactersPerLine(16)
.noAntiAliasing,
os.pwd / "sandbox" / "assets" / "generated"
)
.toSourceFiles((Compile / sourceManaged).value)
}
)

lazy val perf =
Expand Down
Binary file added indigo/sandbox/assets/generated/TestFont.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import indigoextras.effectmaterials.RefractionEntity

object SandboxAssets {

val testFont: AssetName = AssetName("test font")
val testFontMaterial: Material.ImageEffects = Material.ImageEffects(testFont)

val captainName: AssetName = AssetName("captain clown nose")
val captainMaterial: Material.Bitmap = Material.Bitmap(captainName)

Expand Down Expand Up @@ -71,6 +74,7 @@ object SandboxAssets {

def assets: Set[AssetType] =
Set(
AssetType.Image(testFont, AssetPath("assets/generated/TestFont.png")),
AssetType.Font(pixelFont, AssetPath(s"assets/fonts/${pixelFont.toString}.woff2")),
AssetType.Image(smallFontName, AssetPath("assets/boxy_font.png")),
AssetType.Image(light, AssetPath("assets/light_texture.png")),
Expand Down
37 changes: 19 additions & 18 deletions indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.example.sandbox.scenes.TimelineScene
import com.example.sandbox.scenes.UVShaders
import com.example.sandbox.scenes.UiScene
import com.example.sandbox.scenes.UltravioletScene
import example.TestFont
import indigo.*
import indigo.json.Json
import indigo.scenes._
Expand All @@ -48,7 +49,7 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb
val viewportHeight: Int = gameHeight * magnificationLevel // 256

def initialScene(bootData: SandboxBootData): Option[SceneName] =
Some(CameraWithCloneTilesScene.name)
Some(TextScene.name)

def scenes(bootData: SandboxBootData): NonEmptyList[Scene[SandboxStartupData, SandboxGameModel, SandboxViewModel]] =
NonEmptyList(
Expand Down Expand Up @@ -102,24 +103,24 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb
SandboxAssets.assets ++
Shaders.assets ++
Archetype.assets
).withFonts(Fonts.fontInfo)
.withSubSystems(
FPSCounter[SandboxGameModel](
Point(5, 165),
BindingKey("fps counter")
)
)
.withShaders(
Shaders.circle,
Shaders.external,
Shaders.sea,
LegacyEffects.entityShader,
Archetype.shader,
UVShaders.circle,
UVShaders.voronoi,
UVShaders.redBlend
).withFonts(
Fonts.fontInfo,
TestFont.fontInfo
).withSubSystems(
FPSCounter[SandboxGameModel](
Point(5, 165),
BindingKey("fps counter")
)
.addShaders(Refraction.shaders)
).withShaders(
Shaders.circle,
Shaders.external,
Shaders.sea,
LegacyEffects.entityShader,
Archetype.shader,
UVShaders.circle,
UVShaders.voronoi,
UVShaders.redBlend
).addShaders(Refraction.shaders)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.example.sandbox.SandboxAssets
import com.example.sandbox.SandboxGameModel
import com.example.sandbox.SandboxStartupData
import com.example.sandbox.SandboxViewModel
import example.TestFont
import indigo._
import indigo.scenes._

Expand Down Expand Up @@ -53,7 +54,9 @@ object TextScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxView
Layer(
Batch(
Text("The quick brown fox\njumps over the\nlazy dog.", Fonts.fontKey, textMaterial)
.moveTo(10, 10)
.moveTo(10, 10),
Text("The quick brown fox\njumps over the\nlazy dog.", TestFont.fontKey, SandboxAssets.testFontMaterial)
.moveTo(10, 100)
)
).withMagnification(1)
)
Expand Down

0 comments on commit f45f436

Please sign in to comment.