Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[RPG TEMPLATE] Texture Cache
-
Just a small peice of the RPG template.. if the community would like i can post updates along the way. for thosenwho dont know what im talking about.
RPG Template
is just a easy import providing the core mechanics andlogic for rpg development. currently provides character attribute system, experience and leveling system. texture handling is about 1/2 way there and im currently building the item and inventory system.doing this to try n help other that just want a fast poject to play with. if you have never constructed a rpg core structure before i can tell ou its no fast project.. lol if people would like regular updates just mention it in comments snd if there is any lol ill post. good day 🤓😉
Thought i would share this small class to cache game Textures. has came in handy for myself and my fellow developers. Hopfully it will help others in thiers.
Its pretty simply.. just creat a file named
assets
then once an instance is created it will walk through all files and folders within nd get any files ending with.png
or.PNG
it will then take the file name and split it at%
. first section will be used as the name used to call on the cached texture.example:
`iron-ore%mining-stone.png` ⇢ cached[file.split('%')[0]] = scene.Texture("iron-ore%mining-stone.png") then to use the cached texture `ASSETS('iron-ore')` gives cached `_scene2.Texture object`
Hope this helps out anyone 🙃🤓😉
from os import (walk, getcwd, path) from scene import Texture class Assets: def __init__(self): self.cached = dict({}) self.CacheAssets() def __call__(self, name): return self.cached[name] def PrintCache(self): for k, v in self.cached.items(): print(f'{k}\n\t{v}\n{"*"*42}') def CacheAssets(self): id: int = 0 for r, d, f in walk(getcwd()+'/assets/'): for file in f: if file.endswith(".png") or file.endswith(".PNG"): id += 1 if '%' in file: name: str = file.split('%')[0] self.cached[name] = Texture(path.join(r, file)) else: self.cached[f'{id}'] = Texture(path.join(r, file)) ASSETS = Assets() ASSETS.PrintCache()