Beispiel #1
0
import signal
from multiprocessing import Process
from multiprocessing.managers import BaseManager

import octogon.config
import octogon.scoreboard
from octogon.server import OctogonServerProcess
from octogon.api.smashgg import SmashAPI
from octogon.daemon.scss import SCSSAutoCompiler
from octogon.gui.window import OctogonWindow
from octogon.renderer import Renderer
from octogon.utils.logger import get_print_fn

print = get_print_fn()


class Flags:
    """
    A container of objects that need to be shared
    between multiple processes.
    """
    def __init__(self):
        self.scoreboard = None
        self.is_scoreboard_modified = True

    def set_scoreboard_modified(self, value):
        self.is_scoreboard_modified = value

    def get_scoreboard_modified(self):
        return self.is_scoreboard_modified
Beispiel #2
0
    QPushButton,
    QStackedWidget,
    QWidget,
    QSizePolicy,
)
from PyQt5.QtCore import QMargins

import typing
from octogon.utils.logger import get_print_fn
from octogon.gui.layouts.scoreboard import ScoreboardLayout
from octogon.gui.layouts.overlays import OverlaysLayout

if typing.TYPE_CHECKING:
    from octogon.gui.window import OctogonWindow

print = get_print_fn("qt")


class TabLayout(QGridLayout):
    """The QT layout that displays tabs."""
    def __init__(self, window: "OctogonWindow"):
        super().__init__()

        self.setContentsMargins(QMargins(0, 0, 0, 0))
        self.setSpacing(0)

        self.btn_scoreboard = QPushButton("scoreboard", parent=window)
        self.btn_scoreboard.clicked.connect(lambda: self.set_tab(0))
        self.btn_overlays = QPushButton("overlays", parent=window)
        self.btn_overlays.clicked.connect(lambda: self.set_tab(1))
Beispiel #3
0
import logging
from typing import TYPE_CHECKING
from multiprocessing import Process

from flask import Flask
from flask_cors import CORS

from octogon.utils.logger import get_print_fn
import octogon.server.router as router

if TYPE_CHECKING:
    from octogon import Octogon

print = get_print_fn("flask")


class OctogonServer:
    def __init__(self, octogon: "Octogon"):

        self.octogon = octogon

        self.app = Flask("Octogon")
        self.cors = CORS(self.app)
        self.app.config["CACHE_TYPE"] = "null"
        self.app.config["CORS_HEADERS"] = "Content-Type"
        self.app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 0

        # disable info logging for flask
        logging.getLogger("werkzeug").setLevel(logging.WARNING)

        router.add_routes(self)
Beispiel #4
0
import os
import random

from jinja2 import Environment, FileSystemLoader

from octogon.api.smashgg.player import PlayerData
from octogon.utils.lookup import get_portrait_url
from octogon.utils.tag import div, span
from octogon.utils.logger import get_print_fn

print = get_print_fn("web")


class HTMLTemplate:
    """
    An HTML template used to serve a browser source.
    """
    def __init__(self, path: str, env: Environment):

        # the Jinja template
        self.template = env.get_template(path)

    def render(self, **kwargs) -> str:
        """
        Render this template as bytes.
        Makes it simpler to write to a HTTP request handler.
        """

        output = self.template.render(**kwargs)
        # print(output)
        return output
Beispiel #5
0
import json

from octogon.utils.data import NestedDict
from octogon.utils.logger import get_print_fn

print = get_print_fn("scoreboard")


class ScoreboardData(NestedDict):
    """
    A reference to the JSON file containing
    scoreboard data.
    """

    DEFAULT = {
        "round_title": "Round 1",
        "round_games": "3",
        "p1": {
            "tag": "",
            "name": "Player 1",
            "color": "Default",
            "wins": 0,
            "character": "Captain Falcon",
            "port": 0,
        },
        "p2": {
            "tag": "",
            "name": "Player 2",
            "color": "Default",
            "wins": 0,
            "character": "Fox",
Beispiel #6
0
import os
from pathlib import Path

from scss.compiler import Compiler
from watchdog.events import FileModifiedEvent, FileSystemEventHandler
from watchdog.observers import Observer

from octogon.utils.logger import get_print_fn

print = get_print_fn("scss")


class SCSSAutoCompiler(FileSystemEventHandler):
    """Handles the automatic compilation of .scss files."""

    # output directory of the compiled .css files
    OUTPUT_DIR = "site/style"

    def __init__(self, octogon):

        config = octogon.config

        self.octogon = octogon
        self.observer = Observer()
        self.observer.schedule(self, path=config.STYLE_PATH, recursive=True)
        self.batch_compile(config.STYLE_PATH)

    def start(self) -> Observer:
        self.observer.setDaemon(True)
        self.observer.start()
Beispiel #7
0
import json
import os
import requests
from octogon.utils import defaultdict
from octogon.api.smashgg.tournament import TournamentData
from octogon.api.smashgg.response import SmashggResponse
from octogon.api.smashgg.player import PlayerData
from octogon.api.smashgg.event import EventData
from octogon.utils.logger import get_print_fn

print = get_print_fn("smash.gg")


class SmashAPI:

    PATH: str = "queries/"

    def __init__(self, octogon):

        config = octogon.config

        self.queries = {}

        files = [
            os.path.join(SmashAPI.PATH, f)
            for f in os.listdir(SmashAPI.PATH)
            if os.path.isfile(os.path.join(SmashAPI.PATH, f))
        ]

        print("loading queries...")
        for filepath in files: