# Path: de/hochschuletrier/jpy/candidates/Candidate.py
# class Candidate(object):
# 	def __init__(self, id, color, name="", points=0):
# 		self.name = StringVar()
# 		self.points = IntVar()
# 		self.color = color
# 		self.id = id
# 		if points != 0:
# 			self.points.set(points)
# 		if name == "":
# 			self.name.set("Player " + str(self.id + 1))
# 		else:
# 			self.name.set(name)
# 
# 	def addPoints(self, points):
# 		oldPoints = self.points.get()
# 		oldPoints += points
# 		self.points.set(oldPoints)
# 
# 	def subPoints(self, points):
# 		oldPoints = self.points.get()
# 		oldPoints -= points
# 		self.points.set(oldPoints)
# 
# class SerializableCandidate:
# 	def __init__(self, id, name, points):
# 		self.id = int(id)
# 		self.name = str(name)
# 		self.points = int(points)
# 
# 	def default(obj):
# 		if isinstance(obj, SerializableCandidate):
# 			return obj.__dict__
# 		return obj
# 
# Path: de/hochschuletrier/jpy/jason/JSONBackupHandler.py
# class JSONBackupHandler:
# 	def __init__(self, file):
# 		self.file = file
# 
# 	def save(self, data):
# 		with open(self.file, 'w') as outfile:
# 			json.dump(data, outfile, default=SerializableCandidate.default)
# 
# 	def load(self):
# 		with open(self.file) as data_file:
# 			jsondata = json.load(data_file)
# 		return jsondata
# 
# Path: de/hochschuletrier/jpy/Constants.py
# class Constants:
# 	SCREENW = 0
# 	SCREENH = 0
# 	COLORS = ["red", "green", "purple", "brown", "black", "yellow"]


from de.hochschuletrier.jpy.candidates.Candidate import Candidate, SerializableCandidate
from de.hochschuletrier.jpy.jason.JSONBackupHandler import JSONBackupHandler
from de.hochschuletrier.jpy.Constants import Constants
__author__ = 'miko'


class CandidateManager:
	def __init__(self, master):
		self.candidates = []
		self.maxCount = 3
		self.master = master
		usebackup = self.master.backupManager.usebackup

		if usebackup:
			backupHandle = JSONBackupHandler("candidates_backup.json")
			self.restoreCandidates(backupHandle.load())
		else:
			self.registerCandidates()

	def registerCandidates(self):
		colors = Constants.COLORS
		for candidate in range(0, self.maxCount):
			self.candidates.append(Candidate(candidate, colors[candidate]))

	def restoreCandidates(self, data):
		for candidate in data:

# Path: de/hochschuletrier/jpy/candidates/Candidate.py
# class Candidate(object):
# 	def __init__(self, id, color, name="", points=0):
# 		self.name = StringVar()
# 		self.points = IntVar()
# 		self.color = color
# 		self.id = id
# 		if points != 0:
# 			self.points.set(points)
# 		if name == "":
# 			self.name.set("Player " + str(self.id + 1))
# 		else:
# 			self.name.set(name)
# 
# 	def addPoints(self, points):
# 		oldPoints = self.points.get()
# 		oldPoints += points
# 		self.points.set(oldPoints)
# 
# 	def subPoints(self, points):
# 		oldPoints = self.points.get()
# 		oldPoints -= points
# 		self.points.set(oldPoints)
# 
# class SerializableCandidate:
# 	def __init__(self, id, name, points):
# 		self.id = int(id)
# 		self.name = str(name)
# 		self.points = int(points)
# 
# 	def default(obj):
# 		if isinstance(obj, SerializableCandidate):
# 			return obj.__dict__
# 		return obj
# 
# Path: de/hochschuletrier/jpy/jason/JSONBackupHandler.py
# class JSONBackupHandler:
# 	def __init__(self, file):
# 		self.file = file
# 
# 	def save(self, data):
# 		with open(self.file, 'w') as outfile:
# 			json.dump(data, outfile, default=SerializableCandidate.default)
# 
# 	def load(self):
# 		with open(self.file) as data_file:
# 			jsondata = json.load(data_file)
# 		return jsondata
# 
# Path: de/hochschuletrier/jpy/Constants.py
# class Constants:
# 	SCREENW = 0
# 	SCREENH = 0
# 	COLORS = ["red", "green", "purple", "brown", "black", "yellow"]


# Path: de/hochschuletrier/jpy/candidates/CandidateManager.py
from de.hochschuletrier.jpy.candidates.Candidate import Candidate, SerializableCandidate
from de.hochschuletrier.jpy.jason.JSONBackupHandler import JSONBackupHandler
from de.hochschuletrier.jpy.Constants import Constants

__author__ = 'miko'


class CandidateManager:
	def __init__(self, master):
		self.candidates = []
		self.maxCount = 3
		self.master = master
		usebackup = self.master.backupManager.usebackup

		if usebackup:
			backupHandle = JSONBackupHandler("candidates_backup.json")
			self.restoreCandidates(backupHandle.load())
		else:
			self.registerCandidates()

	def registerCandidates(self):
		colors = Constants.COLORS
		for candidate in range(0, self.maxCount):
			self.candidates.append(Candidate(candidate, colors[candidate]))

	def restoreCandidates(self, data):
		for candidate in data:

			self.candidates.append(Candidate(candidate["id"], candidate["name"], candidate["points"]))