Skip to content

Commit

Permalink
Run code formatter (#19)
Browse files Browse the repository at this point in the history
* Rename name to overlay_name

* Run prettier code formatter
  • Loading branch information
klaasnicolaas authored Jun 15, 2024
1 parent deb8bdf commit 7c56efe
Showing 1 changed file with 62 additions and 26 deletions.
88 changes: 62 additions & 26 deletions stream_overlays/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""DDS - RotorHazard Stream Overlay Plugin"""

from eventmanager import Evt
from flask import templating
from flask.blueprints import Blueprint

overlays: list = ["DDS", "LCDR"]

class StreamOverlays():

class StreamOverlays:
"""Stream Overlays plugin class."""

def __init__(self, rhapi):
Expand All @@ -25,23 +27,30 @@ def create_panels(self, _args) -> None:
_args: Arguments passed to function.
"""
num_nodes: int = len(self._rhapi.interface.seats)
for name in self._overlays:
base_path: str = f"/stream/overlay/{name.lower()}"
for overlay_name in self._overlays:
base_path: str = f"/stream/overlay/{overlay_name.lower()}"

# Register a panel for each overlay on the streams page
panel_id = f"stream_overlays_{name.lower()}"
self._rhapi.ui.register_panel(panel_id, f"{name} - OBS Overlays", "streams")
panel_id = f"stream_overlays_{overlay_name.lower()}"
self._rhapi.ui.register_panel(
panel_id, f"{overlay_name} - OBS Overlays", "streams"
)

# Create header, link and markdown block for the topbar
topbar_markdown: str = "## Topbar\n"
topbar_markdown += f"- <a href='{base_path}/topbar' target='_blank'>{name} Overlay - Topbar</a>\n"
self._rhapi.ui.register_markdown(panel_id, f"{name}-Topbar", topbar_markdown)
topbar_markdown += f"- <a href='{base_path}/topbar' target='_blank'>{overlay_name} Overlay - Topbar</a>\n"
self._rhapi.ui.register_markdown(
panel_id, f"{overlay_name}-Topbar", topbar_markdown
)

# Create header, links and markdown block for each node overlay (or mock nodes)
nodes_markdown: str = "## Nodes\n"
for i in range(num_nodes):
nodes_markdown += f"- <a href='{base_path}/node/{i+1}' target='_blank'>{name} Overlay - Node {i+1}</a>\n"
self._rhapi.ui.register_markdown(panel_id, f"{name}-Nodes", nodes_markdown)
nodes_markdown += f"- <a href='{base_path}/node/{i+1}' target='_blank'>{overlay_name} Overlay - Node {i+1}</a>\n"
self._rhapi.ui.register_markdown(
panel_id, f"{overlay_name}-Nodes", nodes_markdown
)


def initialize(rhapi):
"""Initialize the plugin.
Expand All @@ -56,31 +65,58 @@ def initialize(rhapi):
rhapi.events.on(Evt.STARTUP, stream_overlays.create_panels)

bp = Blueprint(
'stream_overlays',
"stream_overlays",
__name__,
template_folder='pages',
static_folder='static',
static_url_path='/stream_overlays/static'
template_folder="pages",
static_folder="static",
static_url_path="/stream_overlays/static",
)

@bp.route('/stream/overlay/<string:name>/node/<int:node_id>')
@bp.route("/stream/overlay/<string:name>/node/<int:node_id>")
def render_node_overlay(name: str, node_id: int):
"""Render the node overlay."""
return templating.render_template(f'stream/overlays/node_{name}.html', serverInfo=None, getOption=rhapi.db.option, getConfig=rhapi.config.get_item, __=rhapi.__, node_id=node_id-1)

@bp.route('/stream/overlay/<string:name>/topbar')
return templating.render_template(
f"stream/overlays/node_{name}.html",
serverInfo=None,
getOption=rhapi.db.option,
getConfig=rhapi.config.get_item,
__=rhapi.__,
node_id=node_id - 1,
)

@bp.route("/stream/overlay/<string:name>/topbar")
def render_topbar_overlay(name: str):
"""Render the topbar overlay."""
return templating.render_template(f'stream/topbars/topbar_{name}.html', serverInfo=None, getOption=rhapi.db.option, getConfig=rhapi.config.get_item, __=rhapi.__)

@bp.route('/stream/overlay/<string:name>/leaderboard/<int:class_id>/overall')
return templating.render_template(
f"stream/topbars/topbar_{name}.html",
serverInfo=None,
getOption=rhapi.db.option,
getConfig=rhapi.config.get_item,
__=rhapi.__,
)

@bp.route("/stream/overlay/<string:name>/leaderboard/<int:class_id>/overall")
def render_overall_class_overlay(name: str, class_id: int):
"""Render the overall class leaderboard overlay."""
return templating.render_template(f'stream/leaderboard/{name}/overall.html', serverInfo=None, getOption=rhapi.db.option, getConfig=rhapi.config.get_item, __=rhapi.__, class_id=class_id)

@bp.route('/stream/overlay/<string:name>/leaderboard/<int:class_id>/class')
return templating.render_template(
f"stream/leaderboard/{name}/overall.html",
serverInfo=None,
getOption=rhapi.db.option,
getConfig=rhapi.config.get_item,
__=rhapi.__,
class_id=class_id,
)

@bp.route("/stream/overlay/<string:name>/leaderboard/<int:class_id>/class")
def render_class_leaderboard_overlay(name: str, class_id: int):
"""Render the class leaderboard overlay."""
return templating.render_template(f'stream/leaderboard/{name}/class.html', serverInfo=None, getOption=rhapi.db.option, getConfig=rhapi.config.get_item, __=rhapi.__, class_id=class_id)

rhapi.ui.blueprint_add(bp)
return templating.render_template(
f"stream/leaderboard/{name}/class.html",
serverInfo=None,
getOption=rhapi.db.option,
getConfig=rhapi.config.get_item,
__=rhapi.__,
class_id=class_id,
)

rhapi.ui.blueprint_add(bp)

0 comments on commit 7c56efe

Please sign in to comment.