changeset 898:6924c2cf94e5

fix: exe-bundling not working correctly
author Sam <sam@basx.dev>
date Sun, 11 Feb 2024 19:26:07 +0700
parents fa54a8a1e3e4
children ad961543994b
files semicongine/build.nim semicongine/resources.nim semicongine/text.nim
diffstat 3 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/build.nim	Sun Feb 11 18:47:13 2024 +0700
+++ b/semicongine/build.nim	Sun Feb 11 19:26:07 2024 +0700
@@ -9,7 +9,7 @@
 
 const BLENDER_CONVERT_SCRIPT = currentSourcePath().parentDir().parentDir().joinPath("scripts/blender_gltf_converter.py")
 
-proc semicongine_builddir*(buildname: string, builddir="./build"): string =
+proc semicongine_builddir*(buildname: string, builddir = "./build"): string =
   var platformDir = "unkown"
 
   if defined(linux):
@@ -19,7 +19,7 @@
 
   return builddir / buildname / platformDir / projectName()
 
-proc semicongine_build_switches*(buildname: string, builddir="./build") =
+proc semicongine_build_switches*(buildname: string, builddir = "./build") =
   switch("experimental", "strictEffects")
   switch("experimental", "strictFuncs")
   switch("define", "nimPreviewHashRef")
@@ -27,7 +27,7 @@
   if defined(windows):
     switch("define", "VK_USE_PLATFORM_WIN32_KHR")
     switch("app", "gui")
-  switch("outdir", semicongine_builddir(buildname, builddir=builddir))
+  switch("outdir", semicongine_builddir(buildname, builddir = builddir))
 
 proc semicongine_pack*(outdir: string, bundleType: string, resourceRoot: string) =
   switch("define", "BUNDLETYPE=" & bundleType)
@@ -48,6 +48,8 @@
           exec &"zip -r {outputfile} ."
         elif defined(windows):
           exec &"powershell Compress-Archive * {outputfile}"
+  elif bundleType == "exe":
+    switch("define", "BUILD_RESOURCEROOT=" & joinPath(getCurrentDir(), resourceRoot)) # required for in-exe packing of resources, must be absolute
 
 proc semicongine_zip*(dir: string) =
   withdir dir.parentDir:
--- a/semicongine/resources.nim	Sun Feb 11 18:47:13 2024 +0700
+++ b/semicongine/resources.nim	Sun Feb 11 19:26:07 2024 +0700
@@ -88,15 +88,15 @@
   import std/tables
   import std/sequtils
 
-  proc loadResources(): Table[string, Table[string, string]] {.compileTime.} =
+  const BUILD_RESOURCEROOT* {.strdefine.}: string = ""
 
-    let srcdir = joinPath(parentDir(querySetting(projectFull)), RESOURCEROOT)
-    for kind, moddir in walkDir(srcdir):
+  proc loadResources(): Table[string, Table[string, string]] {.compileTime.} =
+    assert BUILD_RESOURCEROOT != "", "define BUILD_RESOURCEROOT to build for bundle type 'exe'"
+    for kind, moddir in walkDir(BUILD_RESOURCEROOT):
       if kind == pcDir:
         let modname = moddir.splitPath.tail
         result[modname] = Table[string, string]()
         for resourcefile in walkDirRec(moddir, relative = true):
-        # TODO: add Lempel–Ziv–Welch compression or something similar simple
           result[modname][resourcefile] = staticRead(joinPath(moddir, resourcefile))
   const bundledResources = loadResources()
 
--- a/semicongine/text.nim	Sun Feb 11 18:47:13 2024 +0700
+++ b/semicongine/text.nim	Sun Feb 11 19:26:07 2024 +0700
@@ -62,7 +62,7 @@
     dirty: bool                 # is true if any of the attributes changed
     processedText: seq[Rune]    # used to store processed (word-wrapper) text to preserve original
     lastRenderedText: seq[Rune] # stores the last rendered text, to prevent unnecessary updates
-    mesh: Mesh
+    mesh*: Mesh
 
 func `$`*(text: Text): string =
   "\"" & $text.text[0 ..< min(text.text.len, 16)] & "\""
@@ -286,6 +286,3 @@
   inc instanceCounter
 
   result.refresh()
-
-proc initText*(font: Font, text = "", maxLen: int = text.len, color = newVec4f(0.07, 0.07, 0.07, 1), scale = 1'f32, position = newVec2f(), verticalAlignment = VerticalAlignment.Center, horizontalAlignment = HorizontalAlignment.Center, maxWidth = 0'f32): Text =
-  initText(font = font, text = text.toRunes, maxLen = maxLen, color = color, scale = scale, position = position, horizontalAlignment = horizontalAlignment, verticalAlignment = verticalAlignment, maxWidth = maxWidth)