z_mirror/RecipeBook

git clone https://git.raiguard.me/z_mirror/RecipeBook

Caleb HeuerFix GUIs being updated unnecessarily07fe9df

trunk
1.5 KiB48 linesraw
1local main_gui = require("scripts.gui.main")
2
3local allowed_types = {
4  LuaEntityPrototype = true,
5  LuaEquipmentPrototype = true,
6  LuaFluidPrototype = true,
7  LuaItemPrototype = true,
8  LuaRecipePrototype = true,
9  LuaTilePrototype = true,
10}
11
12local remote_interface = {}
13
14--- Open the given page in Recipe Book.
15--- @param player_index uint
16--- @param prototype LuaEntityPrototype|LuaEquipmentPrototype|LuaFluidPrototype|LuaItemPrototype|LuaRecipePrototype|LuaTilePrototype
17--- @return boolean success
18function remote_interface.open_page(player_index, prototype)
19  if not player_index then
20    error("Recipe Book remote interface was not passed a player_index.")
21  end
22  if type(player_index) ~= "number" then
23    error("Recipe Book remote interface was passed an invalid player index.")
24  end
25  if not prototype then
26    error("Recipe Book remote interface was not passed a prototype.")
27  end
28  if not prototype.valid then
29    error("Recipe Book remote interface was passed an invalid prototype object.")
30  end
31  if not allowed_types[prototype.object_name] then
32    error("Recipe Book remote interface was passed an invalid prototype type.")
33  end
34  local player_gui = main_gui.get_or_create(player_index)
35  if player_gui then
36    player_gui:show_page(prototype)
37  end
38  return true
39end
40
41--- Returns the current remote interface version.
42--- Mods should check against this version before calling `open_page` and abort if the version is incorrect.
43--- @return uint
44function remote_interface.version()
45  return 5
46end
47
48remote.add_interface("RecipeBook", remote_interface)