mutators: expanded readme; add ignore_map to difficulty check

This commit is contained in:
UnShame 2018-02-22 01:35:52 +03:00
parent 4a3d7f3fb2
commit 69d2e49b4e
2 changed files with 29 additions and 4 deletions

View file

@ -1,6 +1,11 @@
# Mutators # Mutators
You can turn your mod into a mutator by calling `mod:register_as_mutator(config)` instead of `mod:init_state()`. This way it will show up on the map screen and have additional features and options to control its behavior. You can turn your mod into a mutator by calling `mod:register_as_mutator(config)` instead of `mod:init_state()`. This way it will show up on the map screen and have additional features and options to control its behavior.
Note that you can still have additional options for your mutator in the mod options menu:
``vmf:create_options(options_widgets, false, "Title", "Description")``
## Configuration
The config object is optional but obviously you'd want to provide at least a readable title for your mutator. Here are the default values: The config object is optional but obviously you'd want to provide at least a readable title for your mutator. Here are the default values:
```lua ```lua
@ -24,6 +29,8 @@ The config object is optional but obviously you'd want to provide at least a rea
"survival_harder", "survival_harder",
"survival_hardest" "survival_hardest"
}, },
load_before_these = {},
load_after_these = {},
incompatible_with_all = false, incompatible_with_all = false,
compatible_with_all = false, compatible_with_all = false,
incompatible_with = {}, incompatible_with = {},
@ -70,3 +77,21 @@ Set this to true if you are sure this mutator won't cause any problems. This ove
``compatible_with = {}`` ``compatible_with = {}``
``incompatible_with = {}`` ``incompatible_with = {}``
You can provide a list of names of mutators you know for sure yours does/doesn't work with respectively. `compatible_with` overwrites `incompatible_with_all` and `incompatible_with` overwrites `compatible_with_all` on other mutators. Use these to provide exceptions to `incompatible_with_all` and `compatible_with_all` on this mutator. You can provide a list of names of mutators you know for sure yours does/doesn't work with respectively. `compatible_with` overwrites `incompatible_with_all` and `incompatible_with` overwrites `compatible_with_all` on other mutators. Use these to provide exceptions to `incompatible_with_all` and `compatible_with_all` on this mutator.
``enable_before_these = {},``
``enable_after_these = {},``
You can improve the compatibility of your mutator with other ones by specifiying which mutators should be enabled after or before this one. This can help with mutators that modify the same portions of the game.
# Methods
Mutators have the same methods and event handlers as other mods plus a few additional ones. These are mostly used behind the scenes.
``mutator:get_config()`` - returns the configuration object without `load_before_these/load_after_these` fields. This shouldn't be modified.
``mutator:can_be_enabled(ignore_map)`` - returns whether the difficulty is right for the mutator and that there are no incompatible mutators enabled. `ignore_map` only takes into account the set difficulty and ignores difficulty selection on the map screen before Play button is pressed.
``mutator:supports_current_difficulty(ignore_map)`` - same as the last one only doesn't check for incompatible mutators
``mutator:get_incompatible_mutators(enabled_only)`` - returns an array of incompatible mutators. `enabled_only` only checks for enabled ones.

View file

@ -276,19 +276,19 @@ local function disable_mutator(self)
end end
-- Checks current difficulty and map selection screen settings to determine if a mutator can be enabled -- Checks current difficulty and map selection screen settings to determine if a mutator can be enabled
local function can_be_enabled(self) local function can_be_enabled(self, ignore_map)
if #self:get_incompatible_mutators(true) > 0 then return false end if #self:get_incompatible_mutators(true) > 0 then return false end
return self:supports_current_difficulty() return self:supports_current_difficulty(ignore_map)
end end
local function supports_current_difficulty(self) local function supports_current_difficulty(self, ignore_map)
local mutator_difficulties = self:get_config().difficulties local mutator_difficulties = self:get_config().difficulties
local actual_difficulty = Managers.state and Managers.state.difficulty:get_difficulty() local actual_difficulty = Managers.state and Managers.state.difficulty:get_difficulty()
local right_difficulty = not actual_difficulty or table.has_item(mutator_difficulties, actual_difficulty) local right_difficulty = not actual_difficulty or table.has_item(mutator_difficulties, actual_difficulty)
local map_view = mutators_view.map_view local map_view = not ignore_map and mutators_view.map_view
local map_view_active = map_view and map_view.active local map_view_active = map_view and map_view.active
local right_unapplied_difficulty = false local right_unapplied_difficulty = false