<commit_before>#!/usr/bin/python

## Holds variables and objects that are needed by a bunch of different classes

import pygame
import platform
import os.path as path
import math
from Logger import Debug, Warn, Info

## This needs to move to GameObjects
class UnitType():
	PLAYER = 1
	ENEMY = 2

## This might be better in GameEngine().
class GameState():
	""" Top level game states. """
	MENU = 1
	GAME = 2
	GAMEOVER = 3

def LoadImage(path):
	""" Return a surface containing the image at the given path. """
	surf = None
	path = FixPath(path)
	try:
		surf = pygame.Surface.convert_alpha(pygame.image.load(path))
	except Exception as exc:
		print("Unable to load image at path '" + path + "': " + str(exc))
	return surf

def GTFO():
	""" FUCK THIS SHIT """
	print "FUCK THIS SHIT"
	pygame.quit()
	exit()

def FixPath(p):
	""" Return the correct path format depending on the current system. """
	if platform.system().lower() == 'windows':
		return path.abspath(p.replace('/', '\\'))
	else:
		return path.abspath(p.replace('\\', '/'))

def TileImage(surf):
	"""
		Return a new surface the size of the screen with the given
		surface tiled in both directions.
	"""

	vars = Vars()
	if isinstance(surf, pygame.Surface):
		newsurf = pygame.Surface(vars.ScreenSize)
		widthRepeat = int(math.ceil(newsurf.get_width() / surf.get_width()))
		heightRepeat = int(math.ceil(newsurf.get_height() / surf.get_height()))
		
		(surfW, surfH) = surf.get_size()
		for h in range(0, heightRepeat + 1):
			for w in range(0, widthRepeat + 1):
				newsurf.blit(surf, (w * surfW, h * surfH))
	else:
		return TileImage(LoadImage(surf))
	return newsurf

class Vars():
	## Actual class here.
	class _vars:
		def __init__(self):
			self.__Bounds = None
			self.Paused = False
			self.Running = True
			self.DefaultFontPath = "NoudaEngine/Fonts/profont.ttf"

			self.__MainMenu = None
			self.__UpperState = GameState.MENU
			self.__LevelControl = None
			
			## Input handlers
			self.__CurrentHandler = None
			self.__CurrentHandler_js = None
			self.__ScreenSize = (0, 0)
			
			Info("Global.Vars() has been initialized.")
		
		@property
		def Bounds(self):
			return self.__Bounds
		
		@Bounds.setter
		def Bounds(self, val):
			if isinstance(val, pygame.Rect):
				self.__Bounds = val
			else:
				raise AttributeError("Bounds is not a Rect!")
		
		@property
		def LevelControl(self):
			return self.__LevelControl

		@LevelControl.setter
		def LevelControl(self, var):
			if self.__LevelControl is not None:
				raise AttributeError("LevelControl is already assigned!")
			else:
				self.__LevelControl = var

		@property
		def MainMenu(self):
			return self.__MainMenu
		
		@MainMenu.setter
		def MainMenu(self, var):
			if isinstance(var, Menu.MenuBase):
				self.__MainMenu = var
			else:
				raise TypeError("MainMenu is an invalid type!")
	
		@property
		def UpperState(self):
			return self.__UpperState
		
		@UpperState.setter
		def UpperState(self, var):
			if type(var) is not int:
				raise TypeError("Invalid type for UpperState!")
			else:
				if var > 0 and var < 4:
					self.__UpperState = var
				else:
					raise IndexError("UpperState value out of range!")
	
		@property
		def CurrentLevel(self):
			return self.__CurrentLevel

		@CurrentLevel.setter
		def CurrentLevel(self, var):
			if isinstance(var, LevelBase):
				self.__CurrentLevel = var
			else:
				raise TypeError("CurrentLevel is an invalid instance!")

		@property<commit_msg>Removed some unused stuff from Globals.Var()<commit_after>#!/usr/bin/python

## Holds variables and objects that are needed by a bunch of different classes

import pygame
import platform
import os.path as path
import math
from Logger import Debug, Warn, Info

## This needs to move to GameObjects
class UnitType():
	PLAYER = 1
	ENEMY = 2

## This might be better in GameEngine().
class GameState():
	""" Top level game states. """
	MENU = 1
	GAME = 2
	GAMEOVER = 3

def LoadImage(path):
	""" Return a surface containing the image at the given path. """
	surf = None
	path = FixPath(path)
	try:
		surf = pygame.Surface.convert_alpha(pygame.image.load(path))
	except Exception as exc:
		print("Unable to load image at path '" + path + "': " + str(exc))
	return surf

def FixPath(p):
	""" Return the correct path format depending on the current system. """
	if platform.system().lower() == 'windows':
		return path.abspath(p.replace('/', '\\'))
	else:
		return path.abspath(p.replace('\\', '/'))

def TileImage(surf):
	"""
		Return a new surface the size of the screen with the given
		surface tiled in both directions.
	"""

	vars = Vars()
	if isinstance(surf, pygame.Surface):
		newsurf = pygame.Surface(vars.ScreenSize)
		widthRepeat = int(math.ceil(newsurf.get_width() / surf.get_width()))
		heightRepeat = int(math.ceil(newsurf.get_height() / surf.get_height()))
		
		(surfW, surfH) = surf.get_size()
		for h in range(0, heightRepeat + 1):
			for w in range(0, widthRepeat + 1):
				newsurf.blit(surf, (w * surfW, h * surfH))
	else:
		return TileImage(LoadImage(surf))
	return newsurf

class Vars():
	## Actual class here.
	class _vars:
		def __init__(self):
			self.Running = True
			self.DefaultFontPath = "NoudaEngine/Fonts/profont.ttf"
			
			## Input handlers
			self.__CurrentHandler = None
			self.__CurrentHandler_js = None
			self.__ScreenSize = (0, 0)
			
			Info("Global.Vars() has been initialized.")
		
		## TODO: Make everything that calls this use pygame.display.get_surface() instead
		@property
{'fraction_non_alphanumeric': 0.1196769456681351, 'fraction_numerical': 0.004405286343612335, 'mean_word_length': 3.6692373607540705, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '732169', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1783, 'n_words': 548}