Merge remote-tracking branch 'github/master' into flib

This commit is contained in:
Caleb Heuer
2024-08-13 11:27:03 -06:00
19 changed files with 177 additions and 45 deletions

View File

@@ -1,16 +1,36 @@
---------------------------------------------------------------------------------------------------
Version: 0.14.3
Date: ????
Changes:
---------------------------------------------------------------------------------------------------
Version: 0.14.2
Date: 2024-07-28
Bugfixes:
- [dictionary-lite] Fixed that the first translation in a re-requested batch would be skipped.
- [math] Fixed that the `sum` function was ignoring the first element. (#69)
- Fixed that the `flib_tool_button_light_green` GUI style had a built-in tooltip. (#68)
---------------------------------------------------------------------------------------------------
Version: 0.14.1
Date: 2024-05-10
Changes:
- Adjusted technology slot GUI template to work with Ultimate Research Queue.
Bugfixes:
- Fixed that the technology slot GUI styles did not have selected styles.
---------------------------------------------------------------------------------------------------
Version: 0.14.0
Date: ????
Date: 2024-03-29
Features:
- Added `gui-lite.format_handlers` function.
- Added `gui-templates` module for building various common and/or annoying GUI components, including technology slots.
- Added `gui-templates` module for building various common and/or annoying GUI components. Currently just makes technology slots.
- Added `table.binary_search` function.
- Added `technology` module with various runtime technology-related utilities.
- Added technology slot styles.
- Added require guards to allow requiring flib modules with any syntax without breaking upvalues.
Changes:
- `data_util.create_icons` no longer defines default icon size or scale. (#64)
Bugfixes:
- Fixed `data_util.get_energy_value` not accepting capital `K` as a unit suffix. (#59)
- [dictionary-lite] Maybe fixed that translation batches would not always be re-requested in their entirety due to undefined Lua next() behavior.
- Fixed that dictionary-lite translation batches would not always be re-requested in their entirety due to undefined Lua next() behavior.
---------------------------------------------------------------------------------------------------
Version: 0.13.0
Date: 2023-10-14

View File

@@ -68,10 +68,10 @@ function flib_data_util.create_icons(prototype, new_layers)
-- Over define as much as possible to minimize weirdness: https://forums.factorio.com/viewtopic.php?f=25&t=81980
icons[#icons + 1] = {
icon = v.icon,
icon_size = v.icon_size or prototype.icon_size or 32,
icon_size = v.icon_size or prototype.icon_size,
icon_mipmaps = v.icon_mipmaps or prototype.icon_mipmaps or 0,
tint = v.tint,
scale = v.scale or 1,
scale = v.scale,
shift = v.shift,
}
end

View File

@@ -19,7 +19,7 @@ local table = require("__flib__.table")
--- @field dicts table<string, RawDictionary>
--- @field finished boolean
--- @field key string?
--- @field last_batch_start DictTranslationRequest?
--- @field last_batch_end DictTranslationRequest?
--- @field language string
--- @field received_count integer
--- @field requests table<uint, DictTranslationRequest>
@@ -146,13 +146,12 @@ end
local function request_next_batch(data)
local raw = data.raw
local wip = data.wip --[[@as DictWipData]]
wip.last_batch_start = nil
if wip.finished then
wip.last_batch_end = nil
return false
end
wip.last_batch_end = { language = wip.language, dict = wip.dict, key = wip.key }
local requests, strings = {}, {}
--- @type DictTranslationRequest?
local first_request = nil
for i = 1, game.is_multiplayer() and 5 or 50 do
local string
repeat
@@ -170,16 +169,12 @@ local function request_next_batch(data)
end
local request = { dict = wip.dict, key = wip.key }
requests[i] = request
if not first_request then
first_request = request
end
strings[i] = string
end
if not first_request then
if not requests[1] then
return false -- Finished
end
wip.last_batch_start = first_request
local translator = wip.translator
if not translator.valid or not translator.connected or translator.locale ~= wip.language then
@@ -298,8 +293,18 @@ function flib_dictionary.on_tick()
return
end
if game.tick - wip.request_tick <= request_timeout_ticks then
return
if game.tick - wip.request_tick > request_timeout_ticks then
local request = wip.last_batch_end
if not request then
-- TODO: Remove WIP because we actually finished somehow? This should never happen I think
error("We're screwed")
end
wip.dict = request.dict
wip.finished = false
wip.key = request.key
wip.requests = {}
request_next_batch(data)
update_gui(data)
end
local request = wip.last_batch_start

View File

@@ -219,8 +219,9 @@ end
--- flib_gui.handle_events({ on_button_clicked = on_button_clicked })
--- ```
--- @param input GuiElemHandler|table<defines.events, GuiElemHandler?>
--- @param existing Tags?
--- @return Tags
function flib_gui.format_handlers(input)
function flib_gui.format_handlers(input, existing)
local out
if type(input) == "table" then
out = {}
@@ -230,6 +231,10 @@ function flib_gui.format_handlers(input)
else
out = handlers[input]
end
if existing then
existing[handler_tag_key] = out
return existing
end
return { [handler_tag_key] = out }
end

View File

@@ -9,36 +9,46 @@ local flib_technology = require("__flib__.technology")
local flib_gui_templates = {}
--- Create and return a technology slot.
--- Create and return a technology slot. `on_click` must be a registered GUI handler through `gui-lite`.
--- @param parent LuaGuiElement
--- @param technology LuaTechnology
--- @param level uint
--- @param research_state TechnologyResearchState
--- @param on_click GuiElemHandler?
--- @param tags Tags?
--- @param index uint?
--- @return LuaGuiElement
function flib_gui_templates.technology_slot(parent, technology, level, research_state, on_click)
local progress = flib_technology.get_research_progress(technology, level)
function flib_gui_templates.technology_slot(parent, technology, level, research_state, on_click, tags, index)
local technology_prototype = technology.prototype
local is_multilevel = flib_technology.is_multilevel(technology)
local research_state_str = flib_table.find(flib_technology.research_state, research_state)
local style = "flib_technology_slot_" .. research_state_str
if technology.upgrade or flib_technology.is_multilevel(technology) or technology.prototype.level > 1 then
if technology.upgrade or is_multilevel or technology_prototype.level > 1 then
style = style .. "_multilevel"
end
local base = parent.add({
type = "sprite-button",
name = technology.name,
style = style,
elem_tooltip = { type = "technology", name = technology.name },
tags = tags,
index = index,
})
if on_click then
base.tags = flib_gui.format_handlers({ [defines.events.on_gui_click] = on_click })
base.tags = flib_gui.format_handlers({ [defines.events.on_gui_click] = on_click }, tags)
end
base
.add({ type = "flow", style = "flib_technology_slot_sprite_flow", ignored_by_interaction = true })
.add({ type = "sprite", style = "flib_technology_slot_sprite", sprite = "technology/" .. technology.name })
.add({ type = "flow", name = "icon_flow", style = "flib_technology_slot_sprite_flow", ignored_by_interaction = true })
.add({
type = "sprite",
name = "icon",
style = "flib_technology_slot_sprite",
sprite = "technology/" .. technology.name,
})
if technology.upgrade or flib_technology.is_multilevel(technology) or technology.prototype.level > 1 then
if technology.upgrade or is_multilevel or technology_prototype.level > 1 then
base.add({
type = "label",
name = "level_label",
@@ -47,14 +57,14 @@ function flib_gui_templates.technology_slot(parent, technology, level, research_
ignored_by_interaction = true,
})
end
if flib_technology.is_multilevel(technology) then
local max_level_str = technology.prototype.max_level == flib_math.max_uint and "[img=infinity]"
or tostring(technology.prototype.max_level)
if is_multilevel then
local max_level = technology_prototype.max_level
local max_level_str = max_level == flib_math.max_uint and "[img=infinity]" or tostring(max_level)
base.add({
type = "label",
name = "level_range_label",
style = "flib_technology_slot_level_range_label_" .. research_state_str,
caption = technology.prototype.level .. " - " .. max_level_str,
caption = technology_prototype.level .. " - " .. max_level_str,
ignored_by_interaction = true,
})
end
@@ -65,9 +75,10 @@ function flib_gui_templates.technology_slot(parent, technology, level, research_
ignored_by_interaction = true,
})
local ingredients_len = 0
for i, ingredient in pairs(technology.research_unit_ingredients) do
ingredients_len = i
local ingredients = technology.research_unit_ingredients
local ingredients_len = #ingredients
for i = 1, ingredients_len do
local ingredient = ingredients[i]
ingredients_flow.add({
type = "sprite",
style = "flib_technology_slot_ingredient",
@@ -77,6 +88,8 @@ function flib_gui_templates.technology_slot(parent, technology, level, research_
end
ingredients_flow.style.horizontal_spacing = flib_math.clamp((68 - 16) / (ingredients_len - 1) - 16, -15, -5)
local progress = flib_technology.get_research_progress(technology, level)
base.add({
type = "progressbar",
name = "progressbar",

View File

@@ -10,7 +10,7 @@
"dependencies": [ "base >= 1.2.0" ],
"package": {
"git_publish_branch": "master",
"ignore": [ "crowdin.yml", "imgui.ini", "stylua.toml", "tests" ],
"ignore": [ "crowdin.yml", "imgui.ini", "stylua.toml", "tests", "graphics/slots.xcf" ],
"scripts": {
"prepublish": "factorio-crowdin-sync"
},

View File

@@ -1,4 +1,6 @@
[gui]
flib-settings=الإعدادات
[mod-name]
flib=مكتبة Factorio

View File

@@ -1,2 +1,3 @@
locale-identifier=et
locale-name=Eesti
locale-name=Eesti keel

11
locale/et/flib.cfg Normal file
View File

@@ -0,0 +1,11 @@
[gui]
flib-keep-open=Hoia avatud
flib-search-instruction=Otsi (__CONTROL__focus-search__)
flib-settings=Sätted
flib-finishing=Lõpetab...
flib-translating-dictionaries=Tõlgin sõnaraamatuid [img=info]
flib-translating-dictionaries-description=Modidele, mis kasutavad Factorio Teekide sõnaraamatusüsteemi, tuleb pidevalt oma emakeeles tekstiotsinguks tõlkeid lisada. See kasutajaliides näitab igas vajatud keeles iga modi tõlgete kulge. See kasutajaliides eemaldub automaatselt, kui kõik tõlked on lõpule viidud.
[mod-name]
flib=Factorio Teek

View File

@@ -1,5 +1,6 @@
[gui]
flib-keep-open=Garder ouvert
flib-search-instruction=Rechercher (__CONTROL__focus-search__)
flib-settings=Paramètres
flib-finishing=Finalisation...
flib-translating-dictionaries=Traduction des dictionnaires [img=info]

View File

@@ -1,4 +1,6 @@
[gui]
flib-keep-open=Manter aberto
flib-settings=Configurações
[mod-name]

View File

@@ -1,9 +1,11 @@
[gui]
flib-keep-open=ık bırakın
flib-search-instruction=Ara (__CONTROL__focus-search__)
flib-settings=Ayarlar
flib-finishing=Sonlandırılıyor...
flib-translating-dictionaries=Sözlükler çeviriliyor [img=info]
flib-translating-dictionaries-description=Factiorio Library modunun sözlük sistemini kullanan modlar yazılı arama yapabilmek için zamanla çeviri isteği yollar. Bu Grafik Arayüzü yüklü olan her dil için çevirilen modların ilerlemesini görterir. Çevirim tamamlanınca bu arayüz kendi kendini kapatacaktır.
[mod-name]
flib=Factorio Kütüphanesi

View File

@@ -131,7 +131,7 @@ end
--- @param set number[]
--- @return number
function flib_math.sum(set)
local sum = set[2] or 0
local sum = set[1] or 0
for i = 2, #set do
sum = sum + set[i]
end

View File

@@ -151,6 +151,7 @@ styles.flib_tool_button_light_green = {
parent = "item_and_count_select_confirm",
padding = 2,
top_margin = 0,
tooltip = "",
}
styles.flib_tool_button_dark_red = {

View File

@@ -31,6 +31,30 @@ local function build_technology_slot(name, y, level_color, level_range_color)
},
shadow = default_shadow,
},
selected_graphical_set = {
base = {
filename = "__flib__/graphics/technology-slots.png",
position = { 288, y },
size = { 144, 200 },
},
shadow = default_shadow,
},
selected_hovered_graphical_set = {
base = {
filename = "__flib__/graphics/technology-slots.png",
position = { 432, y },
size = { 144, 200 },
},
shadow = default_shadow,
},
selected_clicked_graphical_set = {
base = {
filename = "__flib__/graphics/technology-slots.png",
position = { 432, y },
size = { 144, 200 },
},
shadow = default_shadow,
},
padding = 0,
size = { 72, 100 },
left_click_sound = { filename = "__core__/sound/gui-square-button-large.ogg", volume = 1 },
@@ -62,6 +86,30 @@ local function build_technology_slot(name, y, level_color, level_range_color)
},
shadow = default_shadow,
},
selected_graphical_set = {
base = {
filename = "__flib__/graphics/technology-slots.png",
position = { 864, y },
size = { 144, 200 },
},
shadow = default_shadow,
},
selected_hovered_graphical_set = {
base = {
filename = "__flib__/graphics/technology-slots.png",
position = { 1008, y },
size = { 144, 200 },
},
shadow = default_shadow,
},
selected_clicked_graphical_set = {
base = {
filename = "__flib__/graphics/technology-slots.png",
position = { 1008, y },
size = { 144, 200 },
},
shadow = default_shadow,
},
padding = 0,
size = { 72, 100 },
left_click_sound = { filename = "__core__/sound/gui-square-button-large.ogg", volume = 1 },

View File

@@ -230,7 +230,7 @@ end
--- Call the given function on a set number of items in a table, returning the next starting key.
---
--- Calls `callback(value, key)` over `n` items from `tbl`, starting after `from_k`.
--- Calls `callback(value, key)` over `n` items from `tbl` or until the end is reached, starting after `from_k`.
---
--- The first return value of each invocation of `callback` will be collected and returned in a table keyed by the
--- current item's key.

View File

@@ -18,8 +18,10 @@ function flib_technology.get_research_progress(technology, level)
else
return 0
end
else
elseif technology.level == level then
return force.get_saved_technology_progress(technology) or 0
else
return 0
end
end
@@ -87,6 +89,26 @@ function flib_technology.sort_predicate(tech_a, tech_b)
return tech_a.name < tech_b.name
end
--- Returns the technology's prototype name with the level suffix stripped.
--- @param technology LuaTechnology|LuaTechnologyPrototype
--- @return string
function flib_technology.get_base_name(technology)
local result = string.gsub(technology.name, "%-%d*$", "")
return result
end
--- If the technology is multi-level, returns the technology's base name with that level appended, otherwise returns the technology name.
--- @param technology LuaTechnology
--- @param level uint
--- @return string
function flib_technology.get_leveled_name(technology, level)
if flib_technology.is_multilevel(technology) then
return flib_technology.get_base_name(technology) .. "-" .. level
else
return technology.name
end
end
--- @enum TechnologyResearchState
flib_technology.research_state = {
available = 1,

View File

@@ -290,7 +290,6 @@ function gui.toggle_pinned(self)
self.elems.close_button.tooltip = { "gui.close" }
self.elems.pin_button.sprite = "flib_pin_black"
self.elems.pin_button.style = "flib_selected_frame_action_button"
self.player.opened = self.elems.flib_todo_window
if self.player.opened == self.elems.flib_todo_window then
self.player.opened = nil
end

View File

@@ -93,16 +93,16 @@ end
function Test_sum()
Test.assertEquals(math.sum(values1), 100)
Test.assertEquals(math.sum(values2), 185)
Test.assertEquals(math.sum(values3), -5)
Test.assertEquals(math.sum(values4), -117)
Test.assertEquals(math.sum(values2), 170)
Test.assertEquals(math.sum(values3), -20)
Test.assertEquals(math.sum(values4), -128)
end
function Test_mean()
Test.assertEquals(math.mean(values1), 25)
Test.assertEquals(math.mean(values2), 37)
Test.assertEquals(math.mean(values3), -1)
Test.assertEquals(math.mean(values4), -23.4)
Test.assertEquals(math.mean(values2), 34)
Test.assertEquals(math.mean(values3), -4)
Test.assertEquals(math.mean(values4), -25.6)
end
function Test_midrange()