<commit_before>from serializable import Serializable
from buffalo import utils
from subMap import SubMap
from mapManager import MapManager

import os
import pygame

class Tile(Serializable):
    def __init__(self,pos=(0,0,0),type_id=0,collisionEnabled=False,buildingInternal=False,roofType=0,**kwargs):
        self.pos = pos
        self.type_id = type_id
        self.surface = utils.empty_surface((SubMap.TILE_SIZE,SubMap.TILE_SIZE))
        self.collisionEnabled = collisionEnabled
        self.buildingInternal=buildingInternal
        self.roofType=roofType
        self.inside=False
        self.IMG_FILE = ""
        self.renderedOnce = False
        self.render()

    def render(self):
        self.surface = utils.empty_surface((SubMap.TILE_SIZE,SubMap.TILE_SIZE))
        oldIMG_FILE = self.IMG_FILE
        if self.buildingInternal:
            if self.inside:
                self.IMG_FILE = os.path.join(os.path.join(*list(['tiles','assets'] + [str(self.type_id) + ".png"])))

            else:
                self.IMG_FILE = os.path.join(os.path.join(*list(['tiles','assets'] + [str(self.roofType) + ".png"])))

        else:
            self.IMG_FILE = os.path.join(os.path.join(*list(['tiles','assets'] + [str(self.type_id) + ".png"])))
        
        try:
            self.surface = pygame.image.load(self.IMG_FILE)
        except Exception as e:
            print("Error: Tile image for item \"" + str(self.type_id) + "\" does not exist.")
            print(e)
            self.IMG_FILE = os.path.join(os.path.join(*list(['tiles','assets'] + ["error.png"])))
            self.surface = pygame.image.load(self.IMG_FILE)
        self.renderedOnce = True

    def loadIDProperties(self):
        pass<commit_msg>Reduced File IO / Render Times<commit_after>from serializable import Serializable
from buffalo import utils
from subMap import SubMap
from mapManager import MapManager

import os
import pygame

class Tile(Serializable):
    LOADED_SURFACES = dict()
    def __init__(self,pos=(0,0,0),type_id=0,collisionEnabled=False,buildingInternal=False,roofType=0,**kwargs):
        self.pos = pos
        self.type_id = type_id
        self.surface = utils.empty_surface((SubMap.TILE_SIZE,SubMap.TILE_SIZE))
        self.collisionEnabled = collisionEnabled
        self.buildingInternal=buildingInternal
        self.roofType=roofType
        self.inside=False
        self.render()

    def render(self):
        renderID = self.type_id
        if self.buildingInternal and not self.inside:
            renderID = self.roofType
        self.surface = Tile.loadSurfaceForId(renderID)

        

    def loadIDProperties(self):
        pass

    @staticmethod
    def loadSurfaceForId(_id):
        if _id in Tile.LOADED_SURFACES.keys():
            return Tile.LOADED_SURFACES[_id]
        IMG_FILE = os.path.join(os.path.join(*list(['tiles','assets'] + [str(_id) + ".png"])))
        try:
            surface = pygame.image.load(IMG_FILE)
            Tile.LOADED_SURFACES[_id] = surface
            return surface
        except Exception as e:
            print("Error: Tile image for item \"" + str(_id) + "\" does not exist.")
            print(e)
            IMG_FILE = os.path.join(os.path.join(*list(['tiles','assets'] + ["error.png"])))
            surface = pygame.image.load(IMG_FILE)
            Tile.LOADED_SURFACES[_id] = surface
            return surface
{'fraction_non_alphanumeric': 0.12101534828807556, 'fraction_numerical': 0.0029515938606847697, 'mean_word_length': 2.616862326574173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4947590', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1058, 'n_words': 190}