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