Skip to content

Commit

Permalink
moved some magic kwargs into constructor to allow for more automatic …
Browse files Browse the repository at this point in the history
…documentation.
  • Loading branch information
petteramland committed Oct 15, 2024
1 parent 1e2b113 commit cbe121c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 3 additions & 4 deletions ursina/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ursina.scripts.singleton_decorator import singleton
@singleton
class Ursina(ShowBase):
def __init__(self, title='ursina', icon='textures/ursina.ico', borderless=False, fullscreen=False, size=None, forced_aspect_ratio=None, position=None, vsync=True, editor_ui_enabled=True, window_type='onscreen', development_mode=True, render_mode=None, show_ursina_splash=False, **kwargs):
def __init__(self, title='ursina', icon='textures/ursina.ico', borderless=False, fullscreen=False, size=None, forced_aspect_ratio=None, position=None, vsync=True, editor_ui_enabled=True, window_type='onscreen', development_mode=True, render_mode=None, show_ursina_splash=False, use_ingame_console=False, **kwargs):
"""The main class of Ursina. This class is a singleton, so you can only have one instance of it.
Keyword Args (optional):
Expand Down Expand Up @@ -126,7 +126,7 @@ def __init__(self, title='ursina', icon='textures/ursina.ico', borderless=False,

if application.window_type != 'none':
window.make_editor_gui()
if 'use_ingame_console' in kwargs and kwargs['use_ingame_console']:
if use_ingame_console:
import builtins
from ursina import Entity, TextField, color
window.console = Entity(parent=window.editor_ui, position=window.top_left, z=-999, eternal=True)
Expand All @@ -150,8 +150,7 @@ def _console_text_input(key):
window.console.text_input = _console_text_input


if 'editor_ui_enabled' in kwargs:
window.editor_ui.enabled = kwargs['editor_ui_enabled']
window.editor_ui.enabled = editor_ui_enabled

print('package_folder:', application.package_folder)
print('asset_folder:', application.asset_folder)
Expand Down
20 changes: 12 additions & 8 deletions ursina/prefabs/draggable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
class Draggable(Button):
_z_plane = None

def __init__(self, **kwargs):
def __init__(self, require_key=None, step=Vec3.zero, plane_direction=Vec3.forward, lock=None, min_x=-inf, min_y=-inf, min_z=-inf, max_x=inf, max_y=inf, max_z=inf, **kwargs):
if not __class__._z_plane:
__class__._z_plane = Entity(name='_z_plane', scale=(9999,9999), enabled=False, eternal=True)

super().__init__(**kwargs)
self.require_key = None
self.require_key = require_key
self.dragging = False
self.delta_drag = 0
self.start_pos = self.world_position
self.start_offset = (0,0,0)
self.step = (0,0,0)
self.plane_direction = (0,0,1)
self.lock = Vec3(0,0,0) # set to 1 to lock movement on any of x, y and z axes
self.min_x, self.min_y, self.min_z = -inf, -inf, -inf
self.max_x, self.max_y, self.max_z = inf, inf, inf
self.step = step
self.plane_direction = plane_direction
self.lock = lock if lock else Vec3(0,0,0) # set to 1 to lock movement on any of x, y and z axes
self.min_x = min_x
self.min_y = min_y
self.min_z = min_z
self.max_x = max_x
self.max_y = max_y
self.max_z = max_z

if not Draggable._z_plane.model: # set these after game start so it can load the model
Draggable._z_plane.model = 'quad'
Expand All @@ -27,7 +31,7 @@ def __init__(self, **kwargs):

for key, value in kwargs.items():
if key == 'collider' and value == 'sphere' and self.has_ancestor(camera.ui):
print('error: sphere colliders are not supported on Draggables in ui space.')
raise Exception('error: sphere colliders are not supported on Draggables in ui space.')

if key == 'text' or key in self.attributes:
continue
Expand Down

0 comments on commit cbe121c

Please sign in to comment.