Esempio n. 1
0
    def UnloadSoundTuneCache(self):
        print("ContentManager.UnloadSoundTuneCache : Clearing FrequencyGenerator Cache...")
        self.SoundTuneCache_Cache.clear()
        self.SoundTuneCache_Names.clear()
        Utils.GarbageCollector_Collect()

        del self.SoundTuneCache_Cache
        del self.SoundTuneCache_Names
        Utils.GarbageCollector_Collect()

        self.SoundTuneCache_Cache = list()
        self.SoundTuneCache_Names = list()
        Utils.GarbageCollector_Collect()
        print("ContentManager.UnloadSoundTuneCache : Done")
Esempio n. 2
0
def Shape_Line(DISPLAY, Color, startX, startY, endX, endY, LineWidth, FoldLine=True):
    """
    Draw a Line
    :param DISPLAY:Surface to be drawn
    :param Color:Color (RGB)
    :param startX:Line StartX
    :param startY:Line StartY
    :param endX:Line EndX
    :param endY:Line EndY
    :param LineWidth:Line Width
    :param FoldLine:Fold the line when getting offscreen
    :return:
    """
    # -- Fix the Color Range -- #
    Color = Utils.FixColorRange(Color)

    if FoldLine:
        if endX > DISPLAY.get_width():
            endX = DISPLAY.get_width()
        if endY > DISPLAY.get_height():
            endY = DISPLAY.get_height()

        if startX < 0:
            startX = 0
        if startY < 0:
            startY = 0

    pygame.draw.line(DISPLAY, Color, (startX, startY), (endX, endY), LineWidth)
Esempio n. 3
0
def Shape_Rectangle(DISPLAY, Color, Rectangle, BorderWidth=0, BorderRadius=0, Border_TopLeft_Radius=0, Border_TopRight_Radius=0, Border_BottomLeft_Radius=0, Border_BottomRight_Radius=0, DrawLines=False):
    """
    Draw a Rectangle
    :param DISPLAY:Surface to be drawn\n
    :param Color:Color (RGB)\n
    :param Rectangle:Rectangle Rectangle\n
    :param BorderWidth:Border Width\n
    :param BorderRadius:Border Radius\n
    :param Border_TopLeft_Radius:Only apply border to TopLeft\n
    :param Border_TopRight_Radius:Only apply border to TopRight\n
    :param Border_BottomLeft_Radius:Only apply border to BottomLeft\n
    :param Border_BottomRight_Radius:Only apply border to BottomRight\n
    :param DrawLines:Draw only rectangle line\n
    :return:
    """
    if CntMng.RectangleRenderingDisabled:
        return

    if Rectangle[0] <= DISPLAY.get_width() and Rectangle[0] >= 0 - Rectangle[2] and Rectangle[1] <= DISPLAY.get_height() and Rectangle[1] >= 0 - Rectangle[3]:
        # -- Fix the Color Range -- #
        Color = Utils.FixColorRange(Color)

        # -- Border Radius-- #
        if BorderRadius > 0 and Border_TopRight_Radius == 0 and Border_TopLeft_Radius == 0 and Border_BottomLeft_Radius == 0 and Border_BottomRight_Radius == 0:
            Border_TopRight_Radius = BorderRadius
            Border_TopLeft_Radius = BorderRadius
            Border_BottomRight_Radius = BorderRadius
            Border_BottomLeft_Radius = BorderRadius

        # -- Render the Rectangle -- #
        if not DrawLines:
            pygame.draw.rect(DISPLAY, Color, Rectangle, BorderWidth, BorderRadius, Border_TopLeft_Radius,
                             Border_TopRight_Radius, Border_BottomLeft_Radius, Border_BottomRight_Radius)
        else:
            gFxdraw.rectangle(DISPLAY, Rectangle, Color)
Esempio n. 4
0
    def FontRender(self, DISPLAY, FontFileLocation, Size, Text, ColorRGB, X, Y, antialias=True, Opacity=255):
        """
        Render a Text using a font loaded into Taiyou Font Cache
        :param DISPLAY:Surface Name
        :param FontFileLocation:Font Resource Name [starting with /]
        :param Size:Font Size
        :param Text:Text to be Rendered
        :param ColorRGB:Color in RGB Format [R, G, B]
        :param X:X Location
        :param Y:Y Location
        :param antialias:Smooth Pixels [This option can decrea se peformace]
        :return:
        """
        if not FontRenderingDisabled:
            # -- Get the FontFileObject, required for all functions here -- #
            FontFileObject = self.GetFont_object(FontFileLocation, Size)
            ColorRGB = Utils.FixColorRange(ColorRGB)

            if X <= DISPLAY.get_width() and Y <= DISPLAY.get_height() and X >= -FontFileObject.render(Text, antialias, ColorRGB).get_width() and Y >= -FontFileObject.render(Text, antialias, ColorRGB).get_height() and not Text == "":
                # -- Fix Opacity Range -- #
                if Opacity < 0:
                    Opacity = 0
                if Opacity > 255:
                    Opacity = 255

                # -- Render Multiple Lines -- #
                for i, l in enumerate(Text.splitlines()):
                    # FontSurface Object
                    FontSurface = FontFileObject.render(l, antialias, ColorRGB)

                    # Set Font Opacity
                    FontSurface.set_alpha(Opacity)

                    # Blit Font Surface
                    DISPLAY.blit(FontSurface, (X, Y + Size * i))
Esempio n. 5
0
    def LoadSoundsInFolder(self):
        """
        Load all sounds on the specified folder\n
        :param FolderName:Folder Path Name
        :return:
        """
        if SoundDisabled:
            return

        if self.Sound_Path == "":
            raise Exception("Sound Path was not set.")

        FolderName = self.Sound_Path
        self.InitSoundSystem()

        temp_sound_files = Utils.Directory_FilesList(FolderName)
        index = -1

        print("ContentManager.LoadSoundsInFolder : Loading Sounds")
        for x in temp_sound_files:
            try:
                index += 1
                print("\nContentManager.LoadSoundsInFolder : File[" + x + "] detected; Index[" + str(index) + "]")

                CorrectKeyName = x.replace(FolderName, "")
                self.AllLoadedSounds[CorrectKeyName] = (pygame.mixer.Sound(x))
            except pygame.error:
                break

            print("ContentManager.LoadSoundsInFolder : ItemAdded[" + CorrectKeyName + "]; Index[" + str(index) + "]\n")
        print("ContentManager.LoadSoundsInFolder : Operation Completed")
Esempio n. 6
0
    def UnloadImage(self):
        """
        Unload all loaded sprites
        :return:
        """
        print("Image.Unload : Unloading Images...")
        Utils.GarbageCollector_Collect()
        del self.Images_Data
        del self.Images_Name
        del CurrentLoadedFonts_Name
        Utils.GarbageCollector_Collect()

        self.Images_Data = list()
        self.Images_Name = list()

        print("Image.Unload : Done")
Esempio n. 7
0
    def LoadRegKeysInFolder(self):
        """
        Load all keys on Specified Folder
        :param reg_dir:Specified Folder
        :return:
        """
        if self.Reg_Path == "":
            raise Exception("Registry Path was not set.")

        reg_dir = self.Reg_Path
        # -- FIX for working on Windows -- #
        self.Reg_Path = self.SourceFolder + reg_dir.replace(self.SourceFolder, "")
        self.Reg_Path = self.Reg_Path.replace("/", tge.TaiyouPath_CorrectSlash)

        start_time = time.time()
        # -- Unload the Registry -- #
        self.UnloadRegistry()

        print("Taiyou.ContentManager.LoadRegistry : Loading Registry...")

        temp_reg_keys = Utils.Directory_FilesList(reg_dir)
        index = -1

        for x in temp_reg_keys:
            index += 1

            CorrectKeyName = x.replace(reg_dir, "").replace(".data", "")
            file = open(x, "r")

            CurrentLine = file.read().splitlines()
            AllData = ""
            for x in CurrentLine:
                if not x.startswith("#"):
                    AllData += x + "\n"

            # -- Format the Text -- #
            AllData = AllData.rstrip().replace("%n", "\n").replace("%t", "\t").replace("%s", " ")

            self.reg_keys.append(CorrectKeyName)
            self.reg_contents.append(AllData)

            print("Taiyou.ContentManager.LoadRegistry : KeyLoaded[" + CorrectKeyName + "]")

        print("Taiyou.ContentManager.LoadRegistry : Total of {0} registry keys loaded. In {1} seconds.".format(str(len(self.reg_keys)), Utils.FormatNumber(time.time() - start_time, 4)))

        Utils.GarbageCollector_Collect()
Esempio n. 8
0
def GenerateCrashLog():
    print("Generating crash log...")
    # Create the directory for the Crash Logs
    CrashLogsDir = "./Logs/".replace("/", tge.TaiyouPath_CorrectSlash)
    Utils.Directory_MakeDir(CrashLogsDir)

    try:
        FilePath = CrashLogsDir + SystemFault_ProcessObject.NAME + ".txt"
    except:
        FilePath = CrashLogsDir + "unknow_process_name.txt"

    ProcessInformation = " --- PROCESS INFORMATION ---\n"

    ProcessInformation += "Name:"
    try:
        ProcessInformation += SystemFault_ProcessObject.NAME + "\n"
    except:
        ProcessInformation += "Error while parsing\n"

    ProcessInformation += "PID:"
    try:
        ProcessInformation += SystemFault_ProcessObject.PID + "\n"
    except:
        ProcessInformation += "Error while parsing\n"

    ProcessInformation += "ModulePath:"
    try:
        ProcessInformation += SystemFault_ProcessObject.ROOT_MODULE + "\n"
    except:
        ProcessInformation += "Error while parsing\n"

    ProcessInformation += "IsFullscreen:"
    try:
        ProcessInformation += SystemFault_ProcessObject.FULLSCREEN + "\n"
    except:
        ProcessInformation += "Error while parsing\n"

    ProcessInformation += "HasFocus:"
    try:
        ProcessInformation += SystemFault_ProcessObject.APPLICATION_HAS_FOCUS + "\n"
    except:
        ProcessInformation += "Error while parsing\n"

    ProcessInformation += "TitlebarText:"
    try:
        ProcessInformation += SystemFault_ProcessObject.TITLEBAR_TEXT + "\n"
    except:
        ProcessInformation += "Error while parsing\n"

    ProcessInformation += "\nAny field with 'Error while parsing' was because the process does not actualy have the variable\n\n --- ERROR TRACEBACK ---"

    FileWrite = open(FilePath, "w")
    FileWrite.write(ProcessInformation)
    FileWrite.write(SystemFault_Traceback)
    FileWrite.close()

    print("Crash log completed")
Esempio n. 9
0
    def ReloadRegistry(self):
        """
        Reload all Registry Keys
        :return:
        """
        print("Taiyou.ContentManager.ReloadRegistry : Reloading Registry...")
        self.UnloadRegistry()
        
        self.LoadRegKeysInFolder()

        Utils.GarbageCollector_Collect()
Esempio n. 10
0
    def UnloadRegistry(self):
        """
        Unload all registry keys
        :return:
        """

        # -- Clear the Registry -- #
        print("Taiyou.ContentManager.UnloadRegistry : Unloading Registry")
        self.reg_keys = list()
        self.reg_contents = list()

        Utils.GarbageCollector_Collect()
Esempio n. 11
0
def KillProcessByPID(PID):
    global ProcessListChanged
    Index = GetProcessIndexByPID(PID)

    ProcessList.pop(Index)
    ProcessList_PID.pop(Index)
    ProcessList_Names.pop(Index)
    Utils.GarbageCollector_Collect()

    print("Taiyou : Finished process index: " + str(Index))

    ProcessListChanged = True
Esempio n. 12
0
    def LoadImage(self, ImagePath, Transparency=False):
        """
        Load the Specified Image
        :param ImagePath:Path to the Specified Image
        :param Transparency:Bool Value to import with transparency or not
        :return:
        """
        if Utils.Directory_Exists(ImagePath):
            self.Images_Name.append(tge.TaiyouPath_CorrectSlash + os.path.basename(ImagePath))

            if Transparency:
                self.Images_Data.append(pygame.image.load(ImagePath).convert_alpha())

            else:
                self.Images_Data.append(pygame.image.load(ImagePath).convert())
Esempio n. 13
0
def SetDisplay():
    global DISPLAY
    global ScreenWidth
    global ScreenHeight

    if not tge.RunInFullScreen:
        DISPLAY = pygame.display.set_mode(
            (ScreenWidth, ScreenHeight),
            pygame.DOUBLEBUF | pygame.HWACCEL | pygame.HWSURFACE)

    else:
        DISPLAY = pygame.display.set_mode(
            (ScreenWidth, ScreenHeight), pygame.DOUBLEBUF | pygame.HWACCEL
            | pygame.HWSURFACE | pygame.FULLSCREEN)

    pygame.display.set_caption("Taiyou Framework v" +
                               Utils.FormatNumber(tge.TaiyouGeneralVersion))
Esempio n. 14
0
def Shape_Circle(DISPLAY, X, Y, Radius, Color, Width=0, draw_top_right=False, draw_top_left=False, draw_bottom_left=False, draw_bottom_right=False):
    """
    Draw a Circle
    :param DISPLAY:Surface to draw
    :param X:Circle X
    :param Y:Circle Y
    :param Radius:Circle Radius
    :param Color:Color (RGB)
    :param Width:Circle Width
    :param draw_top_right:Draw top right
    :param draw_top_left:Draw top left
    :param draw_bottom_left:Draw bottom left
    :param draw_bottom_right:Draw bottom right
    :return:
    """
    if X - Radius < DISPLAY.get_width() and Y - Radius < DISPLAY.get_height() and X > -Radius and Y > -Radius and Radius > 1:
        Color = Utils.FixColorRange(Color)

        pygame.draw.circle(DISPLAY, Color, (X, Y), Radius, Width, draw_top_right, draw_top_left, draw_bottom_left, draw_bottom_right)
Esempio n. 15
0
def CreateProcess(Path, ProcessName, pInitArgs=None, pPriority=0):
    """
     Set the Game Object
    :param GameFolder:Folder Path
    :return:
    """
    global ProcessList
    global ProcessList_Names
    global DISPLAY
    global ProcessListChanged
    global ProcessNextPID

    print("TaiyouFramework.CreateProcess : Creating Process: [" + ProcessName +
          "]")

    Path = Path.replace("/", tge.TaiyouPath_CorrectSlash)
    ProcessIndex = len(ProcessList_Names)
    print("ProcessIndex: " + str(ProcessIndex))
    print("Path: " + Path)
    print("ProcessName: " + ProcessName)

    ProcessNextPID += 1

    ProcessList_Names.append(ProcessName)
    Module = importlib.import_module(tge.Get_MainGameModuleName(Path))
    ProcessList.append(
        Module.Process(ProcessNextPID, ProcessName,
                       tge.Get_MainGameModuleName(Path), pInitArgs))
    ProcessList_PID.append(ProcessNextPID)

    importlib.reload(Module)
    del Module

    if tge.Get_MainGameModuleName(Path) in sys.modules:
        sys.modules.pop(tge.Get_MainGameModuleName(Path))
    Utils.GarbageCollector_Collect()

    # Inject Variables and Functions
    Index = ProcessList_PID.index(ProcessNextPID)
    ProcessList[Index].PROCESS_INDEX = ProcessIndex
    ProcessList[Index].WINDOW_DRAG_ENABLED = False
    ProcessList[Index].APPLICATION_HAS_FOCUS = True
    ProcessList[Index].EXECUTABLE_PATH = Path
    ProcessList[Index].PRIORITY = pPriority

    ProcessListChanged = True

    # Initialize
    try:
        # Intialize Process Code
        ProcessList[Index].Initialize()

    except Exception as ex:
        # Remove the last item from the lists
        print("TaiyouFramework.CreateProcess : Process: [" + ProcessName +
              "] thrown an error on while trying to initialize")

        del ProcessList[-1]
        del ProcessList_PID[-1]
        del ProcessList_Names[-1]
        Utils.GarbageCollector_Collect()

        raise ex

    print("TaiyouFramework.CreateProcess : Process: [" + ProcessName +
          "] created successfully.")

    return ProcessNextPID