فهرست منبع

Changed example configuration

Björn Ritzl 11 ماه پیش
والد
کامیت
d5fe6e5bc8
3فایلهای تغییر یافته به همراه80 افزوده شده و 45 حذف شده
  1. 63 0
      examples/_main/examples.lua
  2. 7 4
      examples/_main/loader.script
  3. 10 41
      examples/_main/menu.gui_script

+ 63 - 0
examples/_main/examples.lua

@@ -0,0 +1,63 @@
+local M = {}
+
+local examples = {}
+
+examples["basics"] = { "message_passing", "parent_child", "z_order" }
+examples["factory"] = { "basic", "bullets", "dynamic" }
+examples["movement"] = { "simple_move", "follow", "move_to", "move_forward", "movement_speed", "look_at" }
+examples["physics"] = { "dynamic", "kinematic", "raycast", "trigger", "hinge_joint", "pendulum", "knockback"}
+examples["animation"] = { "euler_rotation", "spinner", "flipbook", "chained_tween", "basic_tween", "spine", "cursor", "easing" }
+examples["gui"] = {
+	"button", "stencil", "load_texture",
+	"progress", "pointer_over", "color",
+	"slice9", "drag", "layouts",
+	"get_set_font", "get_set_texture", "get_set_material",
+}
+examples["input"] = { "move", "text", "down_duration", "mouse_and_touch" }
+examples["material"] = { "vertexcolor", { name = "unlit", nobg = true }, "uvgradient", "noise" }
+examples["particles"] = { "particlefx", "modifiers", "fire_and_smoke" }
+examples["sound"] = { "music", "fade_in_out", "panning" }
+examples["render"] = { "camera", "screen_to_world" }
+examples["debug"] = { "physics", "profile" }
+examples["collection"] = { "proxy", "splash", "timestep" }
+examples["sprite"] = { "size", "tint", "flip", "bunnymark" }
+examples["file"] = { "sys_save_load" }
+examples["tilemap"] = { "collisions", "get_set_tile" }
+examples["timer"] = { "repeating_timer", "trigger_timer", "cancel_timer" }
+examples["resource"] = { "modify_atlas" }
+
+local categories = {}
+for category,_ in pairs(examples) do
+	categories[#categories + 1] = category
+end
+
+for category,examples_in_category in pairs(examples) do
+	for id,example in pairs(examples_in_category) do
+		if type(example) == "string" then
+			examples_in_category[id] = { name = example, nobg = false }
+		end
+	end
+end
+
+local examples_lookup = {}
+for category,examples_in_category in pairs(examples) do
+	for id,example in pairs(examples_in_category) do
+		examples_lookup[category .. "/" .. id] = example
+	end
+end
+
+function M.categories()
+	return categories
+end
+
+function M.category(category)
+	return examples[category]
+end
+
+function M.example(example)
+	return examples_lookup[example]
+end
+
+
+
+return M

+ 7 - 4
examples/_main/loader.script

@@ -1,13 +1,16 @@
+local examples = require("examples._main.examples")
+
 function init(self)
 	self.current_proxy = nil
 	-- Need input focus so it can be trickled down the proxies
 	msg.post(".", "acquire_input_focus")
 
 	-- Start from specific example config or menu
-	local example = sys.get_config("examples.start", nil)
-	print("examples.start", example)
-	if example then
-		msg.post("#", "load_example", { example = hash(example), nomenu = true })
+	local start = sys.get_config("examples.start", nil)
+	if start then
+		local example = examples.example(start)
+		pprint(example)
+		msg.post("#", "load_example", { example = hash(start), nomenu = true, nobg = example.nobg })
 	else
 		msg.post("menu#gui", "show")
 	end

+ 10 - 41
examples/_main/menu.gui_script

@@ -1,3 +1,5 @@
+local examples = require("examples._main.examples")
+
 local function create_layout(items, bl, tr, max_dy)
 	local xi = math.ceil(math.sqrt(items) / 1.5)
 	local yi = math.ceil(items / xi)
@@ -25,7 +27,7 @@ local function create_cat_nodes(self, layout)
 	-- create category nodes
 	self.categories = {}
 	local c = 1
-	for t, cat in ipairs(self.index) do
+	for t, cat in ipairs(examples.categories()) do
 		local p = layout[c]
 		local n = gui.new_text_node(p, cat)
 		gui.set_color(n, vmath.vector4(0.2, 0.2, 0.2, 1.0))
@@ -43,9 +45,9 @@ local function create_example_nodes(self, category, layout)
 	-- create example nodes
 	self.examples = {}
 	local c = 1
-	for t, ex in ipairs(self.index[category]) do
-		local name = type(ex) == "table" and ex.name or ex
-		local nobg = type(ex) == "table" and ex.nobg or false
+	for t, ex in ipairs(examples.category(category)) do
+		local name = ex.name
+		local nobg = ex.nobg
 		local p = layout[c]
 		local n = gui.new_text_node(p, name)
 		gui.set_color(n, vmath.vector4(0.2, 0.2, 0.2, 1.0))
@@ -80,7 +82,7 @@ local function cat_expand(self)
 	local closenode = gui.get_node("close")
 	gui.set_enabled(closenode, true)
 	
-	local ex = self.index[self.current_category]
+	local ex = examples.category(self.current_category)
 	local layout = create_layout(#ex, self.bl, self.tr, 100)
 	create_example_nodes(self, self.current_category, layout)
 end
@@ -101,46 +103,13 @@ local function show_category(self, category)
 end
 
 function init(self)
-	self.index = {}
-	self.index["basics"] = { "message_passing", "parent_child", "z_order" }
-	self.index["factory"] = { "basic", "bullets", "dynamic" }
-	self.index["movement"] = { "simple_move", "follow", "move_to", "move_forward", "movement_speed", "look_at" }
-	self.index["physics"] = { "dynamic", "kinematic", "raycast", "trigger", "hinge_joint", "pendulum", "knockback"}
-	self.index["animation"] = { "euler_rotation", "spinner", "flipbook", "chained_tween", "basic_tween", "spine", "cursor", "easing" }
-	self.index["gui"] = {
-		"button", "stencil", "load_texture",
-		"progress", "pointer_over", "color",
-		"slice9", "drag", "layouts",
-		"get_set_font", "get_set_texture", "get_set_material",
-	}
-	self.index["input"] = { "move", "text", "down_duration", "mouse_and_touch" }
-	self.index["material"] = { "vertexcolor", { name = "unlit", nobg = true }, "uvgradient", "noise" }
-	self.index["particles"] = { "particlefx", "modifiers", "fire_and_smoke" }
-	self.index["sound"] = { "music", "fade_in_out", "panning" }
-	self.index["render"] = { "camera", "screen_to_world" }
-	self.index["debug"] = { "physics", "profile" }
-	self.index["collection"] = { "proxy", "splash", "timestep" }
-	self.index["sprite"] = { "size", "tint", "flip", "bunnymark" }
-	self.index["file"] = { "sys_save_load" }
-	self.index["tilemap"] = { "collisions", "get_set_tile" }
-	self.index["timer"] = { "repeating_timer", "trigger_timer", "cancel_timer" }
-	self.index["resource"] = { "modify_atlas" }
-
-	local categories = {}
-	for k,_ in pairs(self.index) do
-		categories[#categories + 1] = k
-	end
-	for _,category in ipairs(categories) do
-		self.index[#self.index + 1] = category
-	end
-	
 	self.examples = {}
 	self.categories = {}
 
 	self.bl = vmath.vector3(50, 50, 0)
 	self.tr = vmath.vector3(670, 560, 0)
-	
-	local cat_layout = create_layout(#self.index, self.bl, self.tr, 100)
+
+	local cat_layout = create_layout(#examples.categories(), self.bl, self.tr, 100)
 	create_cat_nodes(self, cat_layout)
 	
 	show_categories(self)
@@ -179,7 +148,7 @@ function on_input(self, action_id, action)
 				if gui.pick_node(ex.node, action.x, action.y) then
 					msg.post("/loader#script", "load_example", { example = ex.example, nobg = ex.nobg })
 				end
-			end			
+			end
 		end
 	end
 end