Skip to content

Commit

Permalink
Merge branch 'ahicks/f2.0-research' into f2.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ahicks92 committed Oct 27, 2024
2 parents de4102e + 55dd8db commit 444d457
Show file tree
Hide file tree
Showing 8 changed files with 894 additions and 342 deletions.
292 changes: 17 additions & 275 deletions control.lua

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions locale/en/research.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[fa]
research-menu-title=Research menu

research-not-in-labs=This technology is not researched in a lab and will unlock itself automatically. To find out how to unlock it, press k.
research-enqueued=__1__ added to the research queue.
research-enqueued-front=__1__ added to the front of the research queue.
research-enqueued-back=__1__ added to the back of the research queue.
research-not-enqueued=Unable to enqueue this research.
research-needs-dependencies=Research the requirements for this technology first.
research-queue-empty=Research queue empty.
research-queue-contains=The research queue contains the following: __1__
research-queue-cleared=Research queue cleared.
research-list-changed=The list of technologies changed. Select a research and try again.

# For the research triggers new in 2.0. Should match the format
# research-trigger-x where x comes from the types at
# https://lua-api.factorio.com/stable/concepts/ResearchTrigger.html
research-trigger-craft-item=Craft __1__ X __2__ of __3__ quality.
research-trigger-mine-entity=Mine at least one __1__.
research-trigger-craft-fluid=Craft __1__ X __2__.
research-trigger-capture-spawner=Capture a __1__.
# TODO: there is actually also a quality filter.
research-trigger-build-entity=Builda __1__.
# Also a quality filter here that we aren't handling yet.
research-trigger-send-item-to-orbit=Send __1__ to a space platform.

# These build up a list: requires automation science pack x 1, ...
research-costs-items=Requires __1__.
research-costs-items-entry=__2__ each of __1__
# Shouldn't happen but who knows what other mods will do.
research-costs-nothing=This research costs nothing.
research-needs-techs=Requires researching __1__.
# Needs to match the enum in ResearchList research.lua
research-list-researchable=Available Technologies
research-list-locked=Locked Technologies
research-list-researched=Previously Researched technologies
research-list-no-results=No results for __1__
research-list-no-technologies=No technologies in this category.
# Announced when moving between the list types: "available technologies,
# logistic science". Or when searching.
research-list-moved-up-down=__1__, __2__
research-list-menu-search=__1__ in category __2__

# These fragments are filled in to specify the rewards of a technology, and then
# the fragments are separated by a space. For example, "Description: unlocks
# electronics things. Rewards: unlocks the recipes whatever-the-recipe. Will
# allow research of the-technnology-1, the-technology-2, ... and is also an
# indirect dependency of 10 other technologies". not all fragments are present
# all the time. Note that the bonus modifiers aren't localised by us. That is
# in data/core/locale/*/core.cfg, e.g. provided by Factorio itself. Shnould
# have trailing periods, these form a paragraph.
research-rewards-recipes=Unlocks the following recipes: __1__.
research-rewards-next-researches=Allows researching __1__ immediately.
research-rewards-other-researches=A dependency of __1__ other __plural_for_parameter__1__{1=research|rest=researches}__, which require researching other things to unlock.
research-rewards-tech-infinite=Infinite technology.
research-reward-vanilla-localised-bonus=Adjusts __1__ by __2__.
research-reward-vanilla-localised-bonus-percent=Adjusts __1__ by __2__ percent.
research-reward-gun-speed=Increases __1__ shooting speed by __2__ percent.
research-reward-gun-damage=Increases the damage of __1__ by __2__ percent.
# Nothing is actually other, not literally no reward. Just means the game didn't
# have a bonus variable to change.
research-reward-nothing=Also unlocks __1__.
research-reward-turret-attack=Increases the damage of __1__.
research-reward-give-item=Gives you a __1__ X __2__.
2 changes: 1 addition & 1 deletion scripts/fa-info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ function mod.area_scan_summary_info(pindex, left_top, right_bottom)
table.insert(result, "Area empty")
end

return fa_utils.spacecat_table(result)
return fa_utils.localise_cat_table(result)
end

return mod
11 changes: 7 additions & 4 deletions scripts/fa-utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -931,21 +931,24 @@ end
---@return LocalisedString
mod.spacecat = function(...)
local tab = table.pack(...)
return mod.spacecat_table(tab)
return mod.localise_cat_table(tab)
end

-- Like spacecat but for a table.
-- Like spacecat but for a table, and with custom separator.
---@param tab any[]
---@param sep string? The separator, default space.
---@return LocalisedString
function mod.spacecat_table(tab)
function mod.localise_cat_table(tab, sep)
sep = sep or " "
local will_cat = { "" }

for i = 1, #tab do
local ent = tab[i]
local adding = type(ent) == "table" and ent or tostring(ent)
if adding == nil then adding = "NIL!" end
table.insert(will_cat, adding)
table.insert(will_cat, " ")
-- Careful: shouldn't add after the last element.
if tab[i + 1] then table.insert(will_cat, sep) end
end

-- 21 because 20 params, then the first is the "" part.
Expand Down
7 changes: 7 additions & 0 deletions scripts/localising.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,11 @@ function mod.check_player(pindex)
player.translation_id_lookup[id] = "test_translation"
end

-- Build a localised string which will announce the localised_x field or, if not present, the name.
---@param what { name: string, localised_name: LocalisedString }
---@return LocalisedString
function mod.get_localised_name_with_fallback(what)
assert(what.name)
return { "?", what.localised_name, what.name }
end
return mod
73 changes: 13 additions & 60 deletions scripts/menu-search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local fa_circuits = require("scripts.circuit-networks")
local fa_travel = require("scripts.travel-tools")
local fa_graphics = require("scripts.graphics")
local fa_blueprints = require("scripts.blueprints")
local Research = require("scripts.research")

local mod = {}

Expand All @@ -16,7 +17,7 @@ local function inventory_find_index_of_next_name_match(inv, index, str, pindex)
--Iterate until the end of the inventory for a match
for i = index, #inv, 1 do
local stack = inv[i]
if stack ~= nil and (stack.object_name == "LuaTechnology" or stack.valid_for_read) then
if stack ~= nil and stack.valid_for_read then
local name = string.lower(localising.get(stack.prototype, pindex))
local result = string.find(name, str, 1, true)
if result ~= nil then
Expand All @@ -35,7 +36,7 @@ local function inventory_find_index_of_next_name_match(inv, index, str, pindex)
game.get_player(pindex).play_sound({ path = "inventory-wrap-around" }) --sound for having cicled around
for i = 1, index, 1 do
local stack = inv[i]
if stack ~= nil and (stack.object_name == "LuaTechnology" or stack.valid_for_read) then
if stack ~= nil and stack.valid_for_read then
local name = string.lower(localising.get(stack.prototype, pindex))
local result = string.find(name, str, 1, true)
if result ~= nil then
Expand Down Expand Up @@ -372,47 +373,8 @@ function mod.fetch_next(pindex, str, start_phrase_in)
players[pindex].crafting.lua_recipes
)
elseif players[pindex].menu == "technology" then
--Search the selected tech catagory
local techs = {}
if players[pindex].technology.category == 1 then
techs = players[pindex].technology.lua_researchable
elseif players[pindex].technology.category == 2 then
techs = players[pindex].technology.lua_locked
elseif players[pindex].technology.category == 3 then
techs = players[pindex].technology.lua_unlocked
end
new_index = inventory_find_index_of_next_name_match(techs, search_index, str, pindex)
--Search the second tech category
if new_index <= 0 then
players[pindex].technology.category = players[pindex].technology.category + 1
if players[pindex].technology.category > 3 then players[pindex].technology.category = 1 end
if players[pindex].technology.category == 1 then
techs = players[pindex].technology.lua_researchable
elseif players[pindex].technology.category == 2 then
techs = players[pindex].technology.lua_locked
elseif players[pindex].technology.category == 3 then
techs = players[pindex].technology.lua_unlocked
end
new_index = inventory_find_index_of_next_name_match(techs, search_index, str, pindex)
end
--Search the third tech category
if new_index <= 0 then
players[pindex].technology.category = players[pindex].technology.category + 1
if players[pindex].technology.category > 3 then players[pindex].technology.category = 1 end
if players[pindex].technology.category == 1 then
techs = players[pindex].technology.lua_researchable
elseif players[pindex].technology.category == 2 then
techs = players[pindex].technology.lua_locked
elseif players[pindex].technology.category == 3 then
techs = players[pindex].technology.lua_unlocked
end
new_index = inventory_find_index_of_next_name_match(techs, search_index, str, pindex)
end
--Circle back to the original category if nothing found
if new_index <= 0 then
players[pindex].technology.category = players[pindex].technology.category + 1
if players[pindex].technology.category > 3 then players[pindex].technology.category = 1 end
end
Research.menu_search(pindex, str, 1)
return
elseif players[pindex].menu == "signal_selector" then
--Search the currently selected group
local group_index = players[pindex].signal_selector.group_index
Expand Down Expand Up @@ -485,22 +447,6 @@ function mod.fetch_next(pindex, str, start_phrase_in)
players[pindex].crafting.category = new_index
players[pindex].crafting.index = new_index_2
fa_crafting.read_crafting_slot(pindex, start_phrase)
elseif players[pindex].menu == "technology" then
local techs = {}
local note = start_phrase
if players[pindex].technology.category == 1 then
techs = players[pindex].technology.lua_researchable
note = " researchable "
elseif players[pindex].technology.category == 2 then
techs = players[pindex].technology.lua_locked
note = " locked "
elseif players[pindex].technology.category == 3 then
techs = players[pindex].technology.lua_unlocked
note = " unlocked "
end
players[pindex].menu_search_index = new_index
players[pindex].technology.index = new_index
read_technology_slot(pindex, note)
elseif players[pindex].menu == "signal_selector" then
players[pindex].menu_search_index = new_index
players[pindex].signal_selector.signal_index = new_index
Expand All @@ -526,7 +472,11 @@ function mod.fetch_last(pindex, str)
printout("The open map does not support backwards searching.", pindex)
return
end
if players[pindex].menu ~= "inventory" and players[pindex].menu ~= "building" then
if
players[pindex].menu ~= "inventory"
and players[pindex].menu ~= "building"
and players[pindex].menu ~= "technology"
then
printout(players[pindex].menu .. " menu does not support backwards searching.", pindex)
return
end
Expand Down Expand Up @@ -555,6 +505,9 @@ function mod.fetch_last(pindex, str)
then
inv = game.get_player(pindex).opened.get_output_inventory()
new_index = inventory_find_index_of_last_name_match(inv, search_index, str, pindex)
elseif players[pindex].menu == "technology" then
Research.menu_search(pindex, str, -1)
return
else
printout("This menu or building sector does not support backwards searching.", pindex)
return
Expand Down
Loading

0 comments on commit 444d457

Please sign in to comment.