e
This commit is contained in:
parent
ea74c769c4
commit
ecd52b9d0b
|
@ -1,5 +1,6 @@
|
|||
from Mods.ModMenu import ModTypes
|
||||
|
||||
from .enums import IntEnum, StrEnum, CurrencyType, FrameRate, KeyboardInput
|
||||
from .misc import clsname, combine_flags, is_in_game
|
||||
from .objects import Currency, Player, Settings
|
||||
from .sdkmod import SdkMod
|
||||
|
|
|
@ -1,37 +1,20 @@
|
|||
from enum import IntEnum, auto
|
||||
import enum
|
||||
|
||||
|
||||
class StrEnum(str, enum.Enum):
|
||||
class IntEnum(int, enum.Enum):
|
||||
'Enum with :class:`int` values'
|
||||
|
||||
def __new__(cls, value):
|
||||
return str.__new__(cls, value)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
return int.__new__(cls, value)
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse(cls, value):
|
||||
try:
|
||||
if value in cls:
|
||||
return cls[value]
|
||||
def parse(cls, value) -> 'IntEnum':
|
||||
'''
|
||||
Get an Enum by key or value
|
||||
|
||||
return cls(value)
|
||||
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
for item in cls:
|
||||
if value.upper() in (item.value.upper(), item.name.upper()):
|
||||
return item
|
||||
|
||||
raise KeyError(value)
|
||||
|
||||
|
||||
class IntEnum(enum.IntEnum):
|
||||
@classmethod
|
||||
def parse(cls, value):
|
||||
:param typing.Union[str, int] value: Key or value as a :class:`str` or :class:`int`
|
||||
'''
|
||||
try:
|
||||
if value in cls:
|
||||
return cls[value]
|
||||
|
@ -43,13 +26,48 @@ class IntEnum(enum.IntEnum):
|
|||
|
||||
if isinstance(value, str):
|
||||
for item in cls:
|
||||
if value.upper() == item.name:
|
||||
if value.lower() == item.name.lower():
|
||||
return item
|
||||
|
||||
raise KeyError(value)
|
||||
|
||||
|
||||
class StrEnum(str, enum.Enum):
|
||||
'Enum with :class:`str` values'
|
||||
|
||||
def __new__(cls, value):
|
||||
return str.__new__(cls, value)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
|
||||
@classmethod
|
||||
def parse(cls, value) -> 'StrEnum':
|
||||
'''
|
||||
Get an Enum by key or value
|
||||
|
||||
:param str value: Key or value as a :class:`str`
|
||||
'''
|
||||
try:
|
||||
if value in cls:
|
||||
return cls[value]
|
||||
|
||||
return cls(value)
|
||||
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
for item in cls:
|
||||
if value.lower() in (item.value.lower(), item.name.lower()):
|
||||
return item
|
||||
|
||||
raise KeyError(value)
|
||||
|
||||
|
||||
class CurrencyType(IntEnum):
|
||||
'Type of currency to use with :class:`Mods.ModUtils.Currency`'
|
||||
CREDITS = 0
|
||||
ERIDIUM = 1
|
||||
SERAPH = 2
|
||||
|
@ -66,7 +84,7 @@ class CurrencyType(IntEnum):
|
|||
MAX = 13
|
||||
|
||||
# alias
|
||||
MOONSTONE = CREDITS
|
||||
MOONSTONE = ERIDIUM
|
||||
|
||||
|
||||
class FrameRate(IntEnum):
|
||||
|
@ -147,8 +165,18 @@ class KeyboardInput(StrEnum):
|
|||
F12 = 'F12'
|
||||
|
||||
@classmethod
|
||||
def numbers(cls):
|
||||
def numbers(cls) -> 'tuple[Mods.ModUtils.KeyboardInput]':
|
||||
'All top-row number keys'
|
||||
return tuple(
|
||||
cls.ZERO, cls.ONE, cls.TWO, cls.THREE, cls.FOUR,
|
||||
cls.FIVE, cls.SIX, cls.SEVEN, cls.EIGHT, cls.NINE
|
||||
)
|
||||
|
||||
|
||||
@classmethod
|
||||
def keypad_numbers(cls) -> 'tuple[Mods.ModUtils.KeyboardInput]':
|
||||
'All numberpad number keys'
|
||||
return tuple(
|
||||
cls.NUMPAD_ZERO, cls.NUMPAD_ONE, cls.NUMPAD_TWO, cls.NUMPAD_THREE, cls.NUMPAD_FOUR,
|
||||
cls.NUMPAD_FIVE, cls.NUMPAD_SIX, cls.NUMPAD_SEVEN, cls.NUMPAD_EIGHT, cls.NUMPAD_TEN
|
||||
)
|
||||
|
|
|
@ -30,7 +30,7 @@ def combine_flags(*items) -> enum.Flag:
|
|||
'''
|
||||
Combine multiple :class:`enum.Flag` objects into one
|
||||
|
||||
:param list[str,enum.Flag] items:
|
||||
:param tuple[enum.Flag] items: List of ``Flags`` to be combined
|
||||
'''
|
||||
if len(items) > 1:
|
||||
return functools.reduce(operator.or_, items)
|
||||
|
|
|
@ -7,6 +7,9 @@ class Player:
|
|||
'Represents a player'
|
||||
|
||||
def __init__(self, player):
|
||||
'''
|
||||
:param unrealsdk.UObject player: Player object to work with
|
||||
'''
|
||||
self._player = player
|
||||
self._player.bHasSeenGoldenKeyMessageThisSession = True
|
||||
|
||||
|
|
|
@ -35,6 +35,14 @@ SAVE_STATES = {
|
|||
|
||||
|
||||
class SdkMod(SDKMod):
|
||||
'''
|
||||
Convenience class for ``ModMenu.SDKMod``. Mod options can be accessed like dict items.
|
||||
|
||||
Note: ``Keybinds``, ``Options``, and ``SettingsInputs`` get set on init. This will be
|
||||
changed in the future.
|
||||
'''
|
||||
|
||||
## todo: check if values already exist for Keybinds, Options, and SettingsInput
|
||||
def __new__(cls, *args, **kwargs):
|
||||
instance = SDKMod.__new__(cls, *args, **kwargs)
|
||||
instance.Keybinds = KeybindList()
|
||||
|
@ -54,33 +62,56 @@ class SdkMod(SDKMod):
|
|||
return SDKMod.__getattribute__(self, key)
|
||||
|
||||
|
||||
def get_enable_state(self):
|
||||
def __getitem__(self, key):
|
||||
return self.Options.get(key).CurrentValue
|
||||
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
self.Options.set(key, value)
|
||||
|
||||
|
||||
def __delitem__(self, key):
|
||||
self.Options.set(key)
|
||||
|
||||
|
||||
def get_enable_state(self) -> EnabledSaveType:
|
||||
'Get the stage at which the mod gets auto-enabled'
|
||||
return self.SaveEnabledState
|
||||
|
||||
|
||||
def get_games(self):
|
||||
def get_games(self) -> Game:
|
||||
'Get the flag of supported games'
|
||||
return self.SupportedGames
|
||||
|
||||
|
||||
def get_priority(self):
|
||||
def get_priority(self) -> 'typing.Union[ModPriorities,int]':
|
||||
'Get the init priority'
|
||||
return self.Priority
|
||||
|
||||
|
||||
def get_types(self):
|
||||
def get_types(self) -> ModTypes:
|
||||
'Get the mod categories'
|
||||
return self.Types
|
||||
|
||||
|
||||
def log(self, *data):
|
||||
'Output some text to the in-game console. It will be prefixed with "[{modname}]".'
|
||||
message = ' '.join(str(msg) for msg in data)
|
||||
Log(f'[{self.Name}] {message}')
|
||||
|
||||
|
||||
def register(self):
|
||||
'Register the mod with the mod manager'
|
||||
if is_in_game():
|
||||
RegisterMod(self)
|
||||
|
||||
|
||||
def set_enable_state(self, state):
|
||||
'''
|
||||
Set the stage at which the mod will be auto-enabled
|
||||
|
||||
:param EnabledSaveType state: Stage at which the mod will be auto-enabled
|
||||
'''
|
||||
if isinstance(state, str):
|
||||
state = SAVE_STATES.get(state)
|
||||
|
||||
|
@ -94,6 +125,11 @@ class SdkMod(SDKMod):
|
|||
|
||||
|
||||
def set_games(self, *values):
|
||||
'''
|
||||
Set the games this mod supports
|
||||
|
||||
:param tuple[typing.Union[Game,str]] values: Supported games
|
||||
'''
|
||||
items = []
|
||||
|
||||
for value in values:
|
||||
|
@ -109,6 +145,11 @@ class SdkMod(SDKMod):
|
|||
|
||||
|
||||
def set_priority(self, priority):
|
||||
'''
|
||||
Set the init priority of the mod
|
||||
|
||||
:param typing.Union[ModPriorities,int] priority: Init priority
|
||||
'''
|
||||
if not instance(priority, (int, ModPriorities)):
|
||||
raise TypeError(f'Priority must be an int or ModPriorities, not {type(priority)}')
|
||||
|
||||
|
@ -116,6 +157,11 @@ class SdkMod(SDKMod):
|
|||
|
||||
|
||||
def set_types(self, *types):
|
||||
'''
|
||||
Set the mod's categories
|
||||
|
||||
:param tuple[typing.Union[ModTypes,str]] types: Mod categories
|
||||
'''
|
||||
items = []
|
||||
|
||||
for value in types:
|
||||
|
@ -130,6 +176,61 @@ class SdkMod(SDKMod):
|
|||
self.Types = combine_flags(*items)
|
||||
|
||||
|
||||
## New handler methods for built-in events
|
||||
def handle_disable(self):
|
||||
'Called when the mod gets disabled. Override this in a subclass.'
|
||||
|
||||
|
||||
def handle_enable(self):
|
||||
'Called when the mod gets enabled. Override this in a subclass.'
|
||||
|
||||
|
||||
def handle_game_input(self, bind, event):
|
||||
'''
|
||||
Called when a mod keybind is pressed. Override this in a subclass.
|
||||
|
||||
:param ModMenu.Keybind bind: Keybind associated with the input
|
||||
:param ModMenu.InputEvent event: Type of input
|
||||
'''
|
||||
|
||||
|
||||
@staticmethod
|
||||
def handle_network_deserialize(data):
|
||||
'''
|
||||
Called when data is recieved from a network function. Calls json.loads by default.
|
||||
Override this in a subclass.
|
||||
|
||||
:param str data: JSON data recieved from the network
|
||||
'''
|
||||
|
||||
|
||||
@staticmethod
|
||||
def handle_network_serialize(args):
|
||||
'''
|
||||
Called when data is to be sent over the network. Calls json.dumps by default.
|
||||
Override this in a subclass.
|
||||
|
||||
:param dict data: Data to be sent over the network
|
||||
'''
|
||||
|
||||
|
||||
def handle_option_change(self, option, value):
|
||||
'''
|
||||
Called when a mod option has been changed. Override this in a subclass.
|
||||
|
||||
:param Mods.ModMenu.Options.Value option: Option that recieved the new setting
|
||||
:param typing.Any value: New value to be set to the option
|
||||
'''
|
||||
|
||||
|
||||
def handle_settings_input(self, action):
|
||||
'''
|
||||
Called when a keybind for the mod menu has been pressed. Override this in a subclass.
|
||||
|
||||
:param str action: Name of the action associated with the input
|
||||
'''
|
||||
|
||||
|
||||
## Overriding functions and events to add handler functions for easier sub-classing
|
||||
@classmethod
|
||||
def NetworkDeserialize(cls, data):
|
||||
|
@ -174,35 +275,6 @@ class SdkMod(SDKMod):
|
|||
self.handle_settings_input(action)
|
||||
|
||||
|
||||
## New handler methods for built-in events
|
||||
def handle_disable(self):
|
||||
pass
|
||||
|
||||
|
||||
def handle_enable(self):
|
||||
pass
|
||||
|
||||
|
||||
def handle_game_input(self, bind, event):
|
||||
pass
|
||||
|
||||
|
||||
def handle_network_deserialize(self, data: str):
|
||||
pass
|
||||
|
||||
|
||||
def handle_network_serialize(self, args: dict):
|
||||
pass
|
||||
|
||||
|
||||
def handle_option_change(self, option, value):
|
||||
pass
|
||||
|
||||
|
||||
def handle_settings_input(self, action):
|
||||
pass
|
||||
|
||||
|
||||
class KeybindList(list):
|
||||
def __init__(self, *keybinds):
|
||||
list.__init__(self)
|
||||
|
|
|
@ -69,4 +69,5 @@ class WebPanel(SdkMod):
|
|||
self.server.start()
|
||||
|
||||
|
||||
WebPanel().register()
|
||||
mod = WebPanel()
|
||||
mod.register()
|
||||
|
|
|
@ -21,7 +21,7 @@ pyversion = '.'.join(str(v) for v in sys.version_info[:2])
|
|||
project = 'Izalia\'s PythonSDK Mods'
|
||||
copyright = '2022, Izalia Mae'
|
||||
author = 'Izalia Mae'
|
||||
release = '0.1'
|
||||
release = '1.0'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
Welcome to PythonSDK & Borderlands 2 Documentation!
|
||||
===================================================
|
||||
Izalia's PythonSDK Mods Documentation
|
||||
=====================================
|
||||
|
|
|
@ -2,23 +2,34 @@ Mods by Izalia Mae
|
|||
==================
|
||||
|
||||
|
||||
|
||||
.. autoclass:: Mods.FpsToggle.FpsToggle
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
|
||||
Download: https://static.barkshark.xyz/bl2mods/fpstoggle/fpstoggle-1.0.zip
|
||||
|
||||
.. autoclass:: Mods.InfiniKeys.InfiniKeys
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
|
||||
Download: https://static.barkshark.xyz/bl2mods/infinikeys/infinikeys-1.0.zip
|
||||
|
||||
.. autoclass:: Mods.LootSplosion.LootSplosion
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
|
||||
Download: https://static.barkshark.xyz/bl2mods/lootsplosion/lootsplosion-1.0.zip
|
||||
|
||||
.. autoclass:: Mods.ModUtils.ModUtils
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
:noindex:
|
||||
|
||||
Download: https://static.barkshark.xyz/bl2mods/modutils/modutils-0.1.zip
|
||||
|
||||
.. autoclass:: Mods.WebPanel.WebPanel
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
|
||||
Download: https://static.barkshark.xyz/bl2mods/webpanel/webpanel-0.1.zip
|
||||
|
|
30
docs/mods/modutils-enums.rst
Normal file
30
docs/mods/modutils-enums.rst
Normal file
|
@ -0,0 +1,30 @@
|
|||
Mod Utilities: Enums
|
||||
====================
|
||||
|
||||
.. autoclass:: Mods.ModUtils.IntEnum
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
:show-inheritance:
|
||||
|
||||
.. autoclass:: Mods.ModUtils.StrEnum
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
:show-inheritance:
|
||||
|
||||
.. autoclass:: Mods.ModUtils.CurrencyType
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
:show-inheritance:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: Mods.ModUtils.FrameRate
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
:show-inheritance:
|
||||
:undoc-members:
|
||||
|
||||
.. autoclass:: Mods.ModUtils.KeyboardInput
|
||||
:members:
|
||||
:exclude-members: __init__, __new__
|
||||
:show-inheritance:
|
||||
:undoc-members:
|
|
@ -5,16 +5,25 @@ Mod Utilities
|
|||
:exclude-members: __init__, __new__
|
||||
|
||||
|
||||
Classes
|
||||
~~~~~~~
|
||||
|
||||
.. autoclass:: Mods.ModUtils.Player
|
||||
:members:
|
||||
|
||||
|
||||
Functions
|
||||
~~~~~~~~~
|
||||
|
||||
.. autofunction:: Mods.ModUtils.clsname
|
||||
.. autofunction:: Mods.ModUtils.combine_flags
|
||||
.. autofunction:: Mods.ModUtils.is_in_game
|
||||
|
||||
|
||||
Classes
|
||||
~~~~~~~
|
||||
|
||||
.. autoclass:: Mods.ModUtils.SdkMod
|
||||
:members:
|
||||
:exclude-members: __init__, __new__, NetworkDeserialize, NetworkSerialise, Disable, Enable, GameInputPressed, ModOptionChanged, SettingsInputPressed
|
||||
:show-inheritance:
|
||||
:no-inherited-members:
|
||||
|
||||
.. autoclass:: Mods.ModUtils.Player
|
||||
:members:
|
||||
|
||||
.. autoclass:: Mods.ModUtils.Currency
|
||||
:members:
|
||||
|
|
|
@ -6,6 +6,7 @@ subtrees:
|
|||
subtrees:
|
||||
- entries:
|
||||
- file: mods/modutils.rst
|
||||
- file: mods/modutils-enums.rst
|
||||
- file: unrealsdk/index.rst
|
||||
title: UnrealSDK
|
||||
subtrees:
|
||||
|
|
Loading…
Reference in a new issue