Skip to content

Commit

Permalink
Added basic logging for server. Improved how server handles server co…
Browse files Browse the repository at this point in the history
…mmands. Added 'help' server command to list and give details on available commands. Change project directory layout
  • Loading branch information
Samuel Senior committed Apr 19, 2020
1 parent 471c5ea commit fee2c17
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 74 deletions.
2 changes: 1 addition & 1 deletion config.txt → config/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pitchShift:0

# Source location of the handbell sound, currently either ReBel or Abel
handbellSource:rebel
rebelBellFileLocation:audio/handbell.wav
rebelBellFileLocation:../audio/handbell.wav
abelBellFileLocation:C:\Program Files (x86)\Abel 3\Bells\hbell.wav

[Other]
Expand Down
Binary file modified img/mainBackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/menuBackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
13 changes: 7 additions & 6 deletions audio.py → src/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from error import Error

class Audio(Log, Error):
def __init__(self, numberOfBells, mixer, config):
def __init__(self, numberOfBells, mixer, config, logFile):

super().__init__()
Log.__init__(self, logFile=logFile)
Error.__init__(self)

self.numberOfBells = numberOfBells
self.config = config
Expand Down Expand Up @@ -48,7 +49,7 @@ def __init__(self, numberOfBells, mixer, config):

def checkGeneratedBells(self):
self.regenerateBells = True
self.bellSpecFileLocation = os.path.join('audio', 'bsf')
self.bellSpecFileLocation = os.path.join("..", "audio", "bsf")
# Check BSF exists
if os.path.isfile(self.bellSpecFileLocation):
# If it doesn't the regenerate bells
Expand Down Expand Up @@ -80,7 +81,7 @@ def checkGeneratedBells(self):

def writeBellSpecFile(self):
self.log("[INFO] Writing bell spec file")
self.bellSpecFileLocation = os.path.join('audio', 'bsf')
self.bellSpecFileLocation = os.path.join("..", "audio", "bsf")
with open(self.bellSpecFileLocation, 'w') as bellSpecFile:
bellSpecFile.write("{}:{}\n".format("scaleName", self.config.get('scale')))
bellSpecFile.write("{}:".format("scale"))
Expand Down Expand Up @@ -170,13 +171,13 @@ def generateBells(self):
pitchShifted_sound = pitchShifted_sound.fade_out(fadeTime)
pitchShifted_sound = pitchShifted_sound.fade_out(fadeTime)

pitchShifted_sound.export(os.path.join('audio', '{}.wav'.format(self.numberOfBells - i)), format='wav')
pitchShifted_sound.export(os.path.join("..", "audio", "{}.wav".format(self.numberOfBells - i)), format='wav')

self.writeBellSpecFile()

def loadBells(self):
import os
self.log("[INFO] Loading in bells")
for i in range(self.numberOfBells):
tmp = pygame.mixer.Sound(os.path.join('audio', '{}.wav'.format(i+1)))
tmp = pygame.mixer.Sound(os.path.join("..", "audio", "{}.wav".format(i+1)))
self.bells[i+1] = tmp
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions client.py → src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from log import Log

class Network(Log):
def __init__(self, frameRate=30):
def __init__(self, logFile, frameRate=30):

super().__init__()
Log.__init__(self, logFile=logFile)

self.frameRate = frameRate

Expand Down
2 changes: 1 addition & 1 deletion config.py → src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

class Config:
def __init__(self, fileName='config.txt'):
def __init__(self, fileName):
self.fileName = fileName
self.config = {'numberOfBells':None, 'ringableBells':None,
'scale':None, 'octaveShift':None, 'pitchShift':None,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion log.py → src/log.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

class Log:
def __init__(self, logFile="log.txt"):
def __init__(self, logFile):
self.logFile = logFile

def clearLog(self):
Expand Down
38 changes: 19 additions & 19 deletions rebel.py → src/rebel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
ReBel v0.2.11
ReBel v0.2.12
author: Samuel M Senior
"""

Expand Down Expand Up @@ -27,12 +27,13 @@


class Rebel(Font, KeyPress, Log):
def __init__(self, menuWidth, menuHeight, mainWidth, mainHeight, configFile='config.txt'):
def __init__(self, menuWidth, menuHeight, mainWidth, mainHeight, configFile=os.path.join("..", "config", "config.txt")):

Font.__init__(self)
KeyPress.__init__(self)
Log.__init__(self)

self.logFile = os.path.join("..", "log", "log.txt")
Log.__init__(self, logFile=self.logFile)
self.clearLog()

self.menuWidth = menuWidth
Expand All @@ -51,8 +52,8 @@ def __init__(self, menuWidth, menuHeight, mainWidth, mainHeight, configFile='con
self.win = pygame.display.set_mode((self.menuWidth, self.menuHeight))
pygame.display.set_caption("ReBel")

self.menuBackground = pygame.image.load(os.path.join("img", "menuBackground.png"))
self.mainBackground = pygame.image.load(os.path.join("img", "mainBackground.png"))
self.menuBackground = pygame.image.load(os.path.join("..", "img", "menuBackground.png"))
self.mainBackground = pygame.image.load(os.path.join("..", "img", "mainBackground.png"))

self.offlineMessage = self.smallFont.render("Server offline...", 1, (255, 0, 0))
self.connectingMessage = self.smallFont.render("Connecting to server...", 1, (50, 50, 50))
Expand All @@ -69,11 +70,18 @@ def __init__(self, menuWidth, menuHeight, mainWidth, mainHeight, configFile='con

self.frameRate = 100

self.network = Network(frameRate=self.frameRate)
self.network = Network(self.logFile, frameRate=self.frameRate)

#pygame.mixer.set_num_channels(self.config.get('numberOfBells'))
#self.audio = Audio(self.config.get('numberOfBells'), pygame.mixer, self.config, os.path.join('audio', 'handbell.wav'))

def quit(self):
if self.offline == False:
self.network.send("clientDisconnect:Disconnecting")
self.log("[INFO] Quitting...")
pygame.quit()
sys.exit(0)

def start(self):
self.menuScreen()

Expand Down Expand Up @@ -119,10 +127,7 @@ def menuScreen(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
run_menu = False
if self.offline == False:
self.network.send("clientDisconnect:Disconnecting")
pygame.quit()
sys.exit(0)
self.quit()

if event.type == pygame.MOUSEBUTTONDOWN:
if self.button_serverConnect.rect.collidepoint(event.pos) and self.connectionActive == False:
Expand Down Expand Up @@ -161,10 +166,7 @@ def menuScreen(self):

if self.button_quit.rect.collidepoint(event.pos):
run_menu = False
if self.offline == False:
self.network.send("clientDisconnect:Disconnecting")
pygame.quit()
sys.exit(0)
self.quit()

for box in self.input_boxes:
pygame.display.update(box.handle_event(event, self.win))
Expand Down Expand Up @@ -250,14 +252,14 @@ def main(self):

self.bells[i+1] = Bell(i+1, location=(x, y), width=width, height=height,
textLocation=(textX, textY),
bellImageFile=os.path.join("img", "handbell.png"))
bellImageFile=os.path.join("..", "img", "handbell.png"))

for i, _ in enumerate(self.config.get('ringableBells')) if len(self.config.get('ringableBells')) < self.config.get('numberOfBells') else enumerate(range(self.config.get('numberOfBells'))):
key = self.config.get('keys')[i]
self.bells[self.config.get('ringableBells')[i]].setKey(self.keyPress(key))

pygame.mixer.set_num_channels(self.config.get('numberOfBells'))
self.audio = Audio(self.config.get('numberOfBells'), pygame.mixer, self.config)
self.audio = Audio(self.config.get('numberOfBells'), pygame.mixer, self.config, self.logFile)

clock = pygame.time.Clock()
pygame.display.update(self.win.blit(self.mainBackground, (0, 0)))
Expand All @@ -268,9 +270,7 @@ def main(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
run_main = False
self.network.send("clientDisconnect:Disconnecting")
pygame.quit()
sys.exit(0)
self.quit()

if event.type == pygame.KEYDOWN:
for bell in self.bells.values():
Expand Down
Loading

0 comments on commit fee2c17

Please sign in to comment.