Skip to content

Commit

Permalink
Changed example configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Oct 9, 2024
1 parent 4b849c6 commit d5fe6e5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 45 deletions.
63 changes: 63 additions & 0 deletions examples/_main/examples.lua
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions examples/_main/loader.script
Original file line number Diff line number Diff line change
@@ -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
Expand Down
51 changes: 10 additions & 41 deletions examples/_main/menu.gui_script
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d5fe6e5

Please sign in to comment.