Factorio: add toggle to disable imported blueprints

This commit is contained in:
Fabian Dill 2021-06-19 01:00:21 +02:00
parent 644d62c915
commit f8fd8b3585
3 changed files with 52 additions and 61 deletions

View File

@ -121,6 +121,8 @@ class Toggle(Option):
def get_option_name(self): def get_option_name(self):
return bool(self.value) return bool(self.value)
class DefaultOnToggle(Toggle):
default = 1
class Choice(Option): class Choice(Option):
def __init__(self, value: int): def __init__(self, value: int):
@ -292,56 +294,30 @@ alttp_options: typing.Dict[str, type(Option)] = {
"shop_item_slots": ShopItemSlots, "shop_item_slots": ShopItemSlots,
} }
mapshuffle = Toggle
compassshuffle = Toggle
keyshuffle = Toggle
bigkeyshuffle = Toggle
hints = Toggle
RandomizeDreamers = Toggle
RandomizeSkills = Toggle
RandomizeCharms = Toggle
RandomizeKeys = Toggle
RandomizeGeoChests = Toggle
RandomizeMaskShards = Toggle
RandomizeVesselFragments = Toggle
RandomizeCharmNotches = Toggle
RandomizePaleOre = Toggle
RandomizeRancidEggs = Toggle
RandomizeRelics = Toggle
RandomizeMaps = Toggle
RandomizeStags = Toggle
RandomizeGrubs = Toggle
RandomizeWhisperingRoots = Toggle
RandomizeRocks = Toggle
RandomizeSoulTotems = Toggle
RandomizePalaceTotems = Toggle
RandomizeLoreTablets = Toggle
RandomizeLifebloodCocoons = Toggle
RandomizeFlames = Toggle
hollow_knight_randomize_options: typing.Dict[str, type(Option)] = { hollow_knight_randomize_options: typing.Dict[str, type(Option)] = {
"RandomizeDreamers": RandomizeDreamers, "RandomizeDreamers": DefaultOnToggle,
"RandomizeSkills": RandomizeSkills, "RandomizeSkills": DefaultOnToggle,
"RandomizeCharms": RandomizeCharms, "RandomizeCharms": DefaultOnToggle,
"RandomizeKeys": RandomizeKeys, "RandomizeKeys": DefaultOnToggle,
"RandomizeGeoChests": RandomizeGeoChests, "RandomizeGeoChests": Toggle,
"RandomizeMaskShards": RandomizeMaskShards, "RandomizeMaskShards": DefaultOnToggle,
"RandomizeVesselFragments": RandomizeVesselFragments, "RandomizeVesselFragments": DefaultOnToggle,
"RandomizeCharmNotches": RandomizeCharmNotches, "RandomizeCharmNotches": Toggle,
"RandomizePaleOre": RandomizePaleOre, "RandomizePaleOre": DefaultOnToggle,
"RandomizeRancidEggs": RandomizeRancidEggs, "RandomizeRancidEggs": Toggle,
"RandomizeRelics": RandomizeRelics, "RandomizeRelics": DefaultOnToggle,
"RandomizeMaps": RandomizeMaps, "RandomizeMaps": Toggle,
"RandomizeStags": RandomizeStags, "RandomizeStags": Toggle,
"RandomizeGrubs": RandomizeGrubs, "RandomizeGrubs": Toggle,
"RandomizeWhisperingRoots": RandomizeWhisperingRoots, "RandomizeWhisperingRoots": Toggle,
"RandomizeRocks": RandomizeRocks, "RandomizeRocks": Toggle,
"RandomizeSoulTotems": RandomizeSoulTotems, "RandomizeSoulTotems": Toggle,
"RandomizePalaceTotems": RandomizePalaceTotems, "RandomizePalaceTotems": Toggle,
"RandomizeLoreTablets": RandomizeLoreTablets, "RandomizeLoreTablets": Toggle,
"RandomizeLifebloodCocoons": RandomizeLifebloodCocoons, "RandomizeLifebloodCocoons": Toggle,
"RandomizeFlames": RandomizeFlames "RandomizeFlames": Toggle
} }
hollow_knight_skip_options: typing.Dict[str, type(Option)] = { hollow_knight_skip_options: typing.Dict[str, type(Option)] = {
@ -428,13 +404,16 @@ class FactorioStartItems(OptionDict):
default = {"burner-mining-drill": 19, "stone-furnace": 19} default = {"burner-mining-drill": 19, "stone-furnace": 19}
factorio_options: typing.Dict[str, type(Option)] = {"max_science_pack": MaxSciencePack, factorio_options: typing.Dict[str, type(Option)] = {
"max_science_pack": MaxSciencePack,
"tech_tree_layout": TechTreeLayout, "tech_tree_layout": TechTreeLayout,
"tech_cost": TechCost, "tech_cost": TechCost,
"free_samples": FreeSamples, "free_samples": FreeSamples,
"visibility": Visibility, "visibility": Visibility,
"starting_items": FactorioStartItems, "starting_items": FactorioStartItems,
"recipe_time": RecipeTime} "recipe_time": RecipeTime,
"imported_blueprints": DefaultOnToggle,
}
class AdvancementGoal(Choice): class AdvancementGoal(Choice):
@ -469,7 +448,11 @@ option_sets = (
if __name__ == "__main__": if __name__ == "__main__":
import argparse import argparse
mapshuffle = Toggle
compassshuffle = Toggle
keyshuffle = Toggle
bigkeyshuffle = Toggle
hints = Toggle
test = argparse.Namespace() test = argparse.Namespace()
test.logic = Logic.from_text("no_logic") test.logic = Logic.from_text("no_logic")
test.mapshuffle = mapshuffle.from_text("ON") test.mapshuffle = mapshuffle.from_text("ON")

View File

@ -6,7 +6,16 @@ require "util"
FREE_SAMPLES = {{ free_samples }} FREE_SAMPLES = {{ free_samples }}
SLOT_NAME = "{{ slot_name }}" SLOT_NAME = "{{ slot_name }}"
SEED_NAME = "{{ seed_name }}" SEED_NAME = "{{ seed_name }}"
--SUPPRESS_INVENTORY_EVENTS = false
{% if not imported_blueprints -%}
function set_permissions()
local group = game.permissions.get_group("Default")
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprints_filtered, false)
end
{%- endif %}
-- Initialize force data, either from it being created or already being part of the game when the mod was added. -- Initialize force data, either from it being created or already being part of the game when the mod was added.
function on_force_created(event) function on_force_created(event)
@ -63,7 +72,7 @@ function update_player(index)
local sent local sent
--player.print(serpent.block(data['pending_samples'])) --player.print(serpent.block(data['pending_samples']))
local stack = {} local stack = {}
--SUPPRESS_INVENTORY_EVENTS = true
for name, count in pairs(samples) do for name, count in pairs(samples) do
stack.name = name stack.name = name
stack.count = count stack.count = count
@ -87,16 +96,14 @@ function update_player(index)
samples[name] = nil -- Remove from the list samples[name] = nil -- Remove from the list
end end
end end
--SUPPRESS_INVENTORY_EVENTS = false
end end
-- Update players upon them connecting, since updates while they're offline are suppressed. -- Update players upon them connecting, since updates while they're offline are suppressed.
script.on_event(defines.events.on_player_joined_game, function(event) update_player(event.player_index) end) script.on_event(defines.events.on_player_joined_game, function(event) update_player(event.player_index) end)
function update_player_event(event) function update_player_event(event)
--if not SUPPRESS_INVENTORY_EVENTS then
update_player(event.player_index) update_player(event.player_index)
--end
end end
script.on_event(defines.events.on_player_main_inventory_changed, update_player_event) script.on_event(defines.events.on_player_main_inventory_changed, update_player_event)
@ -115,6 +122,7 @@ function add_samples(force, name, count)
end end
script.on_init(function() script.on_init(function()
{% if not imported_blueprints %}set_permissions(){% endif %}
global.forcedata = {} global.forcedata = {}
global.playerdata = {} global.playerdata = {}
-- Fire dummy events for all currently existing forces. -- Fire dummy events for all currently existing forces.

View File

@ -94,7 +94,7 @@ Factorio:
visibility: visibility:
none: 0 none: 0
sending: 1 sending: 1
random_tech_ingredients: imported_blueprints: # can be turned off to prevent access to blueprints created outside the current world
on: 1 on: 1
off: 0 off: 0
starting_items: starting_items: