Skip to content

Commit

Permalink
Stuff spawner
Browse files Browse the repository at this point in the history
  • Loading branch information
dextercd committed Jan 4, 2024
1 parent 7a2a6a1 commit 65b9fdb
Show file tree
Hide file tree
Showing 15 changed files with 4,918 additions and 3 deletions.
23 changes: 20 additions & 3 deletions component-explorer/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ imgui = load_imgui({version="1.7.0", mod="Component Explorer"})

---@module 'component-explorer.utils.ce_settings'
local ce_settings = dofile_once("mods/component-explorer/utils/ce_settings.lua")

dofile_once("mods/component-explorer/lua_console.lua")

---@module 'component-explorer.globals'
local globals = dofile_once("mods/component-explorer/globals.lua")

Expand Down Expand Up @@ -48,6 +50,14 @@ local herd_relation = dofile_once("mods/component-explorer/herd_relation.lua")
---@module 'component-explorer.cursor'
local cursor = dofile_once("mods/component-explorer/cursor.lua")

---@module 'component-explorer.spawn_stuff'
local spawn_stuff = dofile_once("mods/component-explorer/spawn_stuff.lua")

-- Not used here right now, but depends on grabbing a function that's only
-- supposed to be accessible during mod init.
---@module 'component-explorer.utils.file_util'
dofile_once("mods/component-explorer/utils/file_util.lua")

local last_frame_run = -1

local is_escape_paused = false
Expand Down Expand Up @@ -110,9 +120,6 @@ function show_view_menu_items()
_, console.open = imgui.MenuItem("Lua Console", sct("CTRL+SHIFT+L"), console.open)
_, entity_list.open = imgui.MenuItem("Entity List", sct("CTRL+SHIFT+K"), entity_list.open)
_, herd_relation.open = imgui.MenuItem("Herd Relation", "", herd_relation.open)
_, wiki_wands.open = imgui.MenuItem("Wiki Wands", "", wiki_wands.open)
_, file_viewer.open = imgui.MenuItem("File Viewer", sct("CTRL+SHIFT+F"), file_viewer.open)
_, translations.open = imgui.MenuItem("Translations", "", translations.open)

local clicked
clicked, entity_picker.open = imgui.MenuItem("Entity Picker...", sct("CTRL+SHIFT+E"), entity_picker.open)
Expand All @@ -125,6 +132,12 @@ function show_view_menu_items()
}))
end

_, spawn_stuff.open = imgui.MenuItem("Spawn Stuff", "", spawn_stuff.open)

_, wiki_wands.open = imgui.MenuItem("Wiki Wands", "", wiki_wands.open)
_, file_viewer.open = imgui.MenuItem("File Viewer", sct("CTRL+SHIFT+F"), file_viewer.open)
_, translations.open = imgui.MenuItem("Translations", "", translations.open)

_, cursor.config_open = imgui.MenuItem("Cursor Config", "", cursor.config_open)

_, globals.open = imgui.MenuItem("Globals", "", globals.open)
Expand Down Expand Up @@ -289,6 +302,10 @@ function update_ui(paused, current_frame_run)
cursor.config_show()
end

if spawn_stuff.open then
spawn_stuff.show()
end

if run_flags.open then
run_flags.show()
end
Expand Down
37 changes: 37 additions & 0 deletions component-explorer/spawn_data/README_MOD_DEVS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Hey mod developer!

Your custom perks, spells, and materials should show up automatically. In the
case of materials, the origin is only deduced correctly when
`ModMaterialFilesGet()` is available. (Only on the beta at the time of writing
this).

Creatures and items use a hardcoded list. See the items.lua and
creatures.lua file for the kind of data it contains. You can append to
this list in your mod if you want your things to show up in Component Explorer.

This is what that would look like:

```lua
-- File: mods/<your mod>/init.lua
ModLuaFileAppend(
"mods/component-explorer/spawn_data/creatures.lua",
"mods/<your mod>/files/ce_creatures.lua"
)
```

```lua
-- File: mods/<your mod>/files/ce_creatures.lua
local creatures = dofile_once("mods/component-explorer/spawn_data/creatures.lua")

table.insert(creatures,
{
file="mods/<your mod>/files/animals/omega_hamis.xml",
herd="spider",
name="$animal_yourmod_omegahamis",
origin="<Your Mod>",
tags="mortal,teleportable_NOT,friend,hittable_NOT"
})
```

After adding that code into your mod, the creature should show up inside
Component Explorer.
57 changes: 57 additions & 0 deletions component-explorer/spawn_data/actions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---@module 'component-explorer.utils.file_util'
local file_util = dofile_once("mods/component-explorer/utils/file_util.lua")

dofile_once("data/scripts/gun/gun_enums.lua")

local function register_origins(origin)
for _, action in ipairs(actions) do
if action.origin == nil then
action.origin = origin
end
end
end

local original_do_mod_appends = do_mod_appends
do_mod_appends = function(appends_for)
if appends_for == "data/scripts/gun/gun_actions.lua" then
register_origins("Vanilla")
else
local mod_id = string.match(appends_for, "mods/([^/]*)")
register_origins(mod_id or "Unknown")
end

original_do_mod_appends(appends_for)
end
dofile("data/scripts/gun/gun_actions.lua")
do_mod_appends = original_do_mod_appends

local actions = actions

for _, action in ipairs(actions) do
action.display_name = GameTextGetTranslatedOrNot(action.name)
action.display_description = GameTextGetTranslatedOrNot(action.description)
end

local action_types = {}

local gun_enums_source = file_util.ModTextFileGetContent("data/scripts/gun/gun_enums.lua")
for k, v in string.gmatch(gun_enums_source, "ACTION_TYPE_([%w_]+)%s*=%s*(%d+)") do
action_types[tonumber(v)] = k
end

local unique_action_types = {}
for i=0,#action_types do
table.insert(unique_action_types, action_types[i])
end

---@param act integer
---@return string
local function action_type_to_name(act)
return action_types[act]
end

return {
actions=actions,
unique_action_types=unique_action_types,
action_type_to_name=action_type_to_name,
}
Loading

0 comments on commit 65b9fdb

Please sign in to comment.