[Orxonox-commit 4611] r9282 - code/branches/presentation2012merge/data/gui/scripts

landauf at orxonox.net landauf at orxonox.net
Sat Jun 9 16:42:19 CEST 2012


Author: landauf
Date: 2012-06-09 16:42:19 +0200 (Sat, 09 Jun 2012)
New Revision: 9282

Modified:
   code/branches/presentation2012merge/data/gui/scripts/ShipSelectionMenu.lua
Log:
quick fix: use tcl instead of shell commands to find ship templates for ship selection

Modified: code/branches/presentation2012merge/data/gui/scripts/ShipSelectionMenu.lua
===================================================================
--- code/branches/presentation2012merge/data/gui/scripts/ShipSelectionMenu.lua	2012-06-09 13:51:51 UTC (rev 9281)
+++ code/branches/presentation2012merge/data/gui/scripts/ShipSelectionMenu.lua	2012-06-09 14:42:19 UTC (rev 9282)
@@ -5,23 +5,23 @@
 P.scrollbarWidth = 13
 P.shipList = {}
 function P.onLoad()
-   local dircmd = "ls -l ../levels/templates/ | awk '{print $9}' | grep \"spaceship\" | sed -e 's/\\.[a-zA-Z]*$//'" -- go to spaceships folder and generate a list of installed shipmodels.
-   os.execute(dircmd .. " > ../levels/templates/.shipmodels") --saves output in a textfile
-   --[[TODO: program a Windows Version / platform independent version here:
-   if string.sub(package.config,1,1) == '\\' then
-           -- Windows
-           dircmd = "dir /b/s"
-   end]]
-   P.createFilterTab("All Ships")
+    orxonox.execute("set shipmodelsfile [open {../levels/templates/.shipmodels} w+]")
+    orxonox.execute("foreach line [glob -directory ../levels/templates/ spaceship*] { regexp {.*/(.*)\\..*} $line matchall match1; puts $shipmodelsfile $match1 }")
+    orxonox.execute("close $shipmodelsfile")
+    P.createFilterTab("All Ships")
 end
 
 function P.createShipList() --generates list with tagged shipmodels
-   P.shipList = {}
-   for line in io.lines("../levels/templates/.shipmodels") do  --checks if shipmodel is included in level file
-    if selectedlevel:hasStartingShip(string.lower(line)) then
-        P.shipList[#P.shipList+1] = string.lower(line)
+    P.shipList = {}
+    file = io.open("../levels/templates/.shipmodels")
+    if file ~= nil then
+        for line in file:lines() do  --checks if shipmodel is included in level file
+            if selectedlevel:hasStartingShip(string.lower(line)) then
+                P.shipList[#P.shipList+1] = string.lower(line)
+            end
+        end
+        --file.close() -- TODO: investigate why close() seems to crash?
     end
-   end
 end
 
 function P.update() --updates listbox with found models




More information about the Orxonox-commit mailing list