示例#1
0
"""Instance-related improvements."""
from typing import Dict, Tuple

from srctools import Entity
from srctools.bsp_transform import trans, Context
from srctools.logger import get_logger

LOGGER = get_logger(__name__)

# Number of OnProxyRelayX pairs we have, plus 1.
RELAY_MAX = 30 + 1


@trans('Proxy limits')
def proxy_limits(ctx: Context):
    """Duplicate proxies when required to allow infinite instance IO."""

    # Proxy name, ProxyRelayX -> new name, new index
    new_names = {}  # type: Dict[Tuple[str, int], Tuple[str, int]]

    # First edit proxy outputs, then edit everything else.
    for orig_proxy in list(ctx.vmf.by_class['func_instance_io_proxy']):
        # Set to max, so the next will be generated immediately.
        cur_num = RELAY_MAX
        newest_proxy = None  # type: Entity
        orig_proxy.remove()  # Remove the original, add new ones.
        proxy_nums = {}  # type: Dict[int, Tuple[Entity, int]]

        proxy_name = orig_proxy['targetname']

        for out in orig_proxy.outputs:
示例#2
0
import importlib.util
import traceback
from abc import ABCMeta, abstractmethod
from enum import Enum
from pathlib import Path
from types import ModuleType
from typing import Dict, Callable

import wx
from semver import VersionInfo
from wx.py import dispatcher

import config
from srctools.logger import get_logger

logger = get_logger()


class Events(Enum):

	RegisterEvent = 'RegisterMenusEvent'
	LogWindowCreated = 'LogWindowEvent'
	UnregisterMenu = 'UnregisterMenuEvent'
	DownloadCompleted = 'DownloadCompleted'
	DownloadStarted = 'DownloadStarted'


class Errors:

	class MenuNotFoundException(Exception):
		pass
示例#3
0
"""Transformations for packing and precaching resources."""
import os
from typing import Set

from srctools.bsp_transform import trans, Context
from srctools.logger import get_logger
from srctools.packlist import FileType, SoundScriptMode, unify_path


LOGGER = get_logger(__name__, 'trans.packing')


@trans('comp_precache_model')
def comp_precache_model(ctx: Context):
    """Force precaching a specific model."""
    already_done = set()  # type: Set[str]
    for ent in ctx.vmf.by_class['comp_precache_model']:
        model = ent['model']
        if os.path.normcase(model) in already_done:
            ent.remove()
            continue
        already_done.add(os.path.normcase(model))

        ent['classname'] = 'prop_dynamic_override'

        # Disable shadows and similar things on this to make it as cheap
        # as possible.
        ent['rendermode'] = '10'
        ent['disableshadowdepth'] = '1'
        ent['disableshadows'] = '1'
        ent['solid'] = '0'
示例#4
0
"""Transformations that can be applied to the BSP file."""
from typing import Callable, Dict, Tuple, List

from srctools import FileSystem, VMF, Output
from srctools.logger import get_logger
from srctools.packlist import PackList

LOGGER = get_logger(__name__, 'bsp_trans')

__all__ = ['Context', 'trans', 'run_transformations']


class Context:
    """Bundles information useful for each transformation.

    This allows them to ignore data they don't use.
    """
    def __init__(
        self,
        filesys: FileSystem,
        vmf: VMF,
        pack: PackList,
    ) -> None:
        self.sys = filesys
        self.vmf = vmf
        self.pack = pack
        self._io_remaps = {}  # type: Dict[Tuple[str, str], List[Output]]

    def add_io_remap(self, name: str, *outputs: Output) -> None:
        """Register an output to be replaced.
示例#5
0
from srctools.game import Game

from srctools import Property, logger, AtomicWriter
from srctools.filesys import FileSystemChain, FileSystem, RawFileSystem, VPKFileSystem
from srctools.props_config import Opt, Config, TYPE

from srctools.scripts.plugin import Source as PluginSource, PluginFinder

__all__ = [
    'LOGGER',
    'parse',
    'OPTIONS',
]

LOGGER = logger.get_logger(__name__)

CONF_NAME = 'srctools.vdf'


def parse(
    path: Path
) -> Tuple[Config, Game, FileSystemChain, Set[FileSystem], PluginFinder, ]:
    """From some directory, locate and parse the config file.

    This then constructs and customises each object according to config
    options.

    The first srctools.vdf file found in a parent directory is parsed.
    If none can be found, it tries to find the first subfolder of 'common/' and
    writes a default copy there. FileNotFoundError is raised if none can be
示例#6
0
"""Transformations for packing and precaching resources."""
import os
from typing import Set

from srctools import Entity
from srctools.bsp_transform import trans, Context
from srctools.logger import get_logger
from srctools.packlist import FileType, SoundScriptMode, unify_path


LOGGER = get_logger(__name__, 'trans.packing')


@trans('comp_precache_model')
def comp_precache_model(ctx: Context):
    """Force precaching a specific model."""
    already_done = set()  # type: Set[str]
    for ent in ctx.vmf.by_class['comp_precache_model']:
        model = ent['model']

        # Precaching implies packing it.
        skinset = {int(skin) for skin in ent['skinset'].split()}
        ctx.pack.pack_file(model, FileType.MODEL, skinset=skinset)

        if os.path.normcase(model) in already_done:
            ent.remove()
            continue
        already_done.add(os.path.normcase(model))
        make_precache_prop(ent)

示例#7
0
    Union,
    Generic,
    Any,
    TypeVar,
    Protocol,
    Optional,
    Callable,
    List,
    Tuple,
    Dict,
    Iterator,
    Iterable,
)

__all__ = ['Manager', 'Slot', 'ItemProto']
LOGGER = get_logger(__name__)


class ItemProto(Protocol):
    """Protocol draggable items satisfy."""
    dnd_icon: img.Handle  # Image for the item.


class ItemGroupProto(ItemProto, Protocol):
    """Additional values required when grouping."""
    dnd_group: Optional[str]  # If set, the group an item belongs to.
    # If only one item is present for a group, it uses this.
    dnd_group_icon: Optional[img.Handle]


ItemT = TypeVar(
示例#8
0
import os
import sys
import webbrowser
from pathlib import Path
from sys import platform
from typing import Union

import wx
from requests import get, RequestException
from semver import VersionInfo

import config
from srctools.logger import get_logger

logger = get_logger("utils")
icon: wx.Icon = None
"""BEE Package Maker icon as wx.Icon object"""


class wxStyles:
    TITLEBAR_ONLY_BUTTON_CLOSE = wx.DEFAULT_FRAME_STYLE ^ wx.MINIMIZE_BOX ^ wx.MAXIMIZE_BOX


class UpdateInfo:

    version: VersionInfo
    url: str
    description: str

    def __init__(self, ver: VersionInfo, url: str, desc: str):
        self.version = ver
示例#9
0
import wx.adv
import wx.py.dispatcher as dispatcher

import aboutWindow
import beeManager
import browser
import config
import logWindow
import pluginSystem
import settingsUI
import utilities
from pluginSystem import Events
from srctools.logger import get_logger

# init important things
LOGGER = get_logger()

if utilities.env == 'dev':
	import importlib


wx.InitAllImageHandlers()


class root(wx.Frame):

	instance: 'root'
	settingsWindowInstance: settingsUI.window = None

	def __init__(self):
		# load plugins
示例#10
0
"""Transformations that can be applied to the BSP file."""
from typing import Callable
from srctools import FileSystem, VMF
from srctools.logger import get_logger
from srctools.packlist import PackList


LOGGER = get_logger(__name__, 'bsp_trans')

__all__ = ['Context', 'trans', 'run_transformations']

TRANSFORMS = {}


class Context:
    """Bundles information useful for each transformation.

    This allows them to ignore data they don't use.
    """
    def __init__(
        self, 
        filesys: FileSystem,
        vmf: VMF,
        pack: PackList,
    ):
        self.sys = filesys
        self.vmf = vmf
        self.pack = pack


TransFunc = Callable[[Context], None]