Skip to content

Commit

Permalink
prototype sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
x2605 committed Oct 4, 2020
1 parent 240b518 commit 2f0d511
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
9 changes: 9 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
---------------------------------------------------------------------------------------------------
Version: 0.3.5
Date: 2020-10-04

Changes:
- In tree GUI, if an entry is a prototype object and it has a sprite then, a sprite icon will be shown at left of key name.
Supported prototypes are listed here.
https://lua-api.factorio.com/1.0.0/Concepts.html#SpritePath

---------------------------------------------------------------------------------------------------
Version: 0.3.4
Date: 2020-09-28
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gvv",
"version": "0.3.4",
"version": "0.3.5",
"title": "Lua API global Variable Viewer (gvv)",
"author": "x2605",
"contact": "",
Expand Down
1 change: 1 addition & 0 deletions modules/search_tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local tree_data = {}
local remove_richkey = function(str)
--local tstr = str:match('^.- %(%[color=[^%[]+]([^%[]+)%[/color]%)$') --LuaObject type string
str = str:gsub('^(.-) %(%[color=[^%[]+][^%[]+%[/color]%)$', '%1')
str = str:gsub('^%[img=[^%[]+](.-)$', '%1')
str = str:gsub('^%[color=[^%[]+](.-)%[/color]$', '%1')
str = str:gsub('^%[(.-)]$', '%1')
str = str:gsub('^%[color=[^%[]+](.-)%[/color]$', '%1')
Expand Down
40 changes: 40 additions & 0 deletions modules/sprite.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- 스프라이트

local Sprite = {}

local prototype_sprite_prefix = {
LuaItemPrototype = 'item/',
LuaEntityPrototype = 'entity/',
LuaTechnologyPrototype = 'technology/',
LuaRecipePrototype = 'recipe/',
LuaFluidPrototype = 'fluid/',
LuaTilePrototype = 'tile/',
LuaVirtualSignalPrototype = 'virtual-signal/',
LuaAchievementPrototype = 'achievement/',
LuaEquipmentPrototype = 'equipment/',
}
local prototype_group_type_sprite_prefix = {
['item-group'] = 'item-group/',
}
local safe_check_func = function(obj, prop)
return obj[prop]
end
local safe_check = function(obj, prop)
local pc, ret = pcall(safe_check_func, obj, prop)
if pc then return ret end
end

Sprite.img = function(obj)
if prototype_sprite_prefix[obj.object_name] then
if safe_check(obj, 'name') and game.is_valid_sprite_path(prototype_sprite_prefix[obj.object_name]..obj.name) then
return '[img='..prototype_sprite_prefix[obj.object_name]..obj.name..']'
end
elseif obj.object_name == 'LuaGroup' and safe_check(obj, 'type') and prototype_group_type_sprite_prefix[obj.type] then
if safe_check(obj, 'name') and game.is_valid_sprite_path(prototype_group_type_sprite_prefix[obj.type]..obj.name) then
return '[img='..prototype_group_type_sprite_prefix[obj.type]..obj.name..']'
end
end
return ''
end

return Sprite
10 changes: 7 additions & 3 deletions modules/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

local Table_to_str = require('modules.table_to_str')
local Util = require('modules.util')
local Sprite = require('modules.sprite')

local Tree = {}

Expand Down Expand Up @@ -231,7 +232,8 @@ Tree.draw_init = function(g, tab, mod_name_OR_luaobj, root_name)
parent_container.add{type = 'flow', name = '_G:'} -- [2]
parent_container['_G:'].visible = false
if type(mod_name_OR_luaobj) == 'table' and type(mod_name_OR_luaobj.__self) == 'userdata' and mod_name_OR_luaobj.object_name then
folder, root = draw_folder(tree_data, parent_container, nil, root_name, root_name..' ([color=blue]'..mod_name_OR_luaobj.object_name..'[/color])')
local img = Sprite.img(mod_name_OR_luaobj)
folder, root = draw_folder(tree_data, parent_container, nil, root_name, root_name..' '..img..'([color=blue]'..mod_name_OR_luaobj.object_name..'[/color])')
else
folder, root = draw_folder(tree_data, parent_container, nil, root_name, root_name..' ([color=1,0.3,0.3,1]'..type(mod_name_OR_luaobj)..'[/color])')
end
Expand Down Expand Up @@ -263,7 +265,8 @@ Tree.draw = function(g, tree_data, opened_folder_tree, tbl, parent_container, pa


if prop_allowed and t == 'table' and type(obj.__self) == 'userdata' and obj.object_name then
folder, label = draw_folder(tree_data, parent_container, parent_label, k, Table_to_str.to_richtext(k, true)..' ([color=blue]'..obj.object_name..'[/color])')
local img = Sprite.img(obj)
folder, label = draw_folder(tree_data, parent_container, parent_label, k, img..Table_to_str.to_richtext(k, true)..' ([color=blue]'..obj.object_name..'[/color])')
if not opened_folder_tree or not opened_folder_tree[k] then
parent_container.children[index].content_container.visible = false
label.parent.folder_sprite.sprite = 'gvv-mod_folder-closed'
Expand Down Expand Up @@ -333,7 +336,8 @@ Tree.draw = function(g, tree_data, opened_folder_tree, tbl, parent_container, pa
tree_data[#tree_data + 1] = {parent = parent_label, object = last_item, key = k, is_folder = false}
label_container.add{type = 'label', name = 'equal_sign', caption = ' = '}
if t == 'table' and type(obj.__self) == 'userdata' and obj.object_name then
last_item = label_container.add{type = 'button', name = '_gvv-mod_key_value', caption = Table_to_str.to_richtext(obj),
local img = Sprite.img(obj)
last_item = label_container.add{type = 'button', name = '_gvv-mod_key_value', caption = img..Table_to_str.to_richtext(obj),
style = 'tree-item-luaobj_gvv-mod', mouse_button_filter = {'right'},
}
else
Expand Down

0 comments on commit 2f0d511

Please sign in to comment.