change singleton to global
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import asyncio
|
from __main__ import networking
|
||||||
from networking.Networking import Networking
|
|
||||||
|
|
||||||
|
|
||||||
class InputHandler:
|
class InputHandler:
|
||||||
@@ -10,7 +9,7 @@ class InputHandler:
|
|||||||
async def handleInputs(self):
|
async def handleInputs(self):
|
||||||
self.isRunning = True
|
self.isRunning = True
|
||||||
while self.isRunning:
|
while self.isRunning:
|
||||||
event = await Networking().getInputEvent()
|
event = await networking.getInputEvent()
|
||||||
self.targets[event["name"]].hit() #Todo
|
self.targets[event["name"]].hit() #Todo
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from networking.Networking import Networking
|
from networking.Networking import Networking
|
||||||
from utils.util import normalizeName
|
from utils.util import normalizeName
|
||||||
|
from __main__ import networking
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
@@ -14,6 +16,6 @@ class Solenoid:
|
|||||||
|
|
||||||
def trigger(self):
|
def trigger(self):
|
||||||
logging.info("Trigger solenoid with name " + self.name)
|
logging.info("Trigger solenoid with name " + self.name)
|
||||||
Networking().triggerSolenoid(self.name)
|
networking.triggerSolenoid(self.name)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ from factories.GameFactory import GameFactory
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
networking = None
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parseCommandLine()
|
args = parseCommandLine()
|
||||||
logging.basicConfig(filename='log.txt', level=logging.INFO)
|
logging.basicConfig(filename='log.txt', level=logging.INFO)
|
||||||
@@ -29,11 +31,12 @@ def defaultOutputServerAddress():
|
|||||||
def defaultInputServerAddress():
|
def defaultInputServerAddress():
|
||||||
return config.SOCKET_PATH + config.INPUT_SOCKET_NAME
|
return config.SOCKET_PATH + config.INPUT_SOCKET_NAME
|
||||||
|
|
||||||
|
|
||||||
def createGame(args):
|
def createGame(args):
|
||||||
print(args)
|
print(args)
|
||||||
NetworkFactory.createNetwork(args.OutputServerAddress, args.InputServerAddress)
|
global networking
|
||||||
gameFactory = GameFactory()
|
networking = NetworkFactory.createNetwork(args.OutputServerAddress, args.InputServerAddress)
|
||||||
game = gameFactory.createGame()
|
game = GameFactory().createGame()
|
||||||
return game
|
return game
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
from networking.Networking import Networking
|
from __main__ import networking
|
||||||
|
|
||||||
|
|
||||||
class Display:
|
class Display:
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def printScore(self, score):
|
def printScore(self, score):
|
||||||
Networking().writeDisplayScore(self.name, score)
|
networking.writeDisplayScore(self.name, score)
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
from config import *
|
from __main__ import networking
|
||||||
from networking.Networking import Networking
|
|
||||||
|
|
||||||
from factories.PlayerStateFactory import PlayerStateFactory
|
from factories.PlayerStateFactory import PlayerStateFactory
|
||||||
from factories.DisplayFactory import DisplayFactory
|
from factories.DisplayFactory import DisplayFactory
|
||||||
@@ -14,7 +13,7 @@ from Game import Game
|
|||||||
|
|
||||||
class GameFactory:
|
class GameFactory:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
displayNames = Networking().getDisplays()['displays']
|
displayNames = networking.getDisplays()['displays']
|
||||||
self.displayFactory = DisplayFactory(displayNames)
|
self.displayFactory = DisplayFactory(displayNames)
|
||||||
specialDisplay = self.displayFactory.createSpecialDisplay()
|
specialDisplay = self.displayFactory.createSpecialDisplay()
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ from networking.Networking import Networking
|
|||||||
class NetworkFactory:
|
class NetworkFactory:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createNetwork(output_server_address, input_server_address):
|
def createNetwork(output_server_address, input_server_address):
|
||||||
Networking(output_server_address, input_server_address)
|
return Networking(output_server_address, input_server_address)
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
from networking.Networking import Networking
|
from __main__ import networking
|
||||||
|
|
||||||
class Lamp:
|
class Lamp:
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
Networking().activateLamp(self)
|
networking.activateLamp(self)
|
||||||
|
|
||||||
def deactivate(self):
|
def deactivate(self):
|
||||||
Networking().deactivateLamp()
|
networking.deactivateLamp()
|
||||||
|
|
||||||
def isActivated(self):
|
def isActivated(self):
|
||||||
Networking().getLamps(self)
|
networking.getLamps(self)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
from lamps.Lamp import Lamp
|
from lamps.Lamp import Lamp
|
||||||
|
|
||||||
|
|
||||||
class LampGroup:
|
class LampGroup:
|
||||||
def __init__(self, lamps):
|
def __init__(self, lamps):
|
||||||
self.lamps = lamps
|
self.lamps = lamps
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ import requests_unixsocket as req
|
|||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
import asyncio
|
import asyncio
|
||||||
from utils.Singleton import Singleton
|
|
||||||
|
|
||||||
|
|
||||||
class Networking(metaclass=Singleton):
|
class Networking:
|
||||||
def __init__(self, output_server_address, input_socket_address):
|
def __init__(self, output_server_address, input_socket_address):
|
||||||
self.server_address = ""
|
self.server_address = ""
|
||||||
self.input_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
self.input_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ class Flipper:
|
|||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
logging.info("Activate flipper with name " + self.name)
|
logging.info("Activate flipper with name " + self.name)
|
||||||
Networking().activateFlipper(self.name)
|
networking.activateFlipper(self.name)
|
||||||
|
|
||||||
def deactivate(self):
|
def deactivate(self):
|
||||||
logging.info("Deactivate flipper with name " + self.name)
|
logging.info("Deactivate flipper with name " + self.name)
|
||||||
Networking().deactivateFlipper(self.name)
|
networking.deactivateFlipper(self.name)
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
class Singleton(type):
|
|
||||||
_instances = {}
|
|
||||||
def __call__(cls, *args, **kwargs):
|
|
||||||
if cls not in cls._instances:
|
|
||||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
|
||||||
return cls._instances[cls]
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user