mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-10 23:28:10 -07:00
Compiler part done
This commit is contained in:
+21
-1
@@ -4,6 +4,8 @@ from flipper.app import App
|
||||
from flipper.assets.icon import file2image
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
ICONS_SUPPORTED_FORMATS = ["png"]
|
||||
|
||||
@@ -23,6 +25,15 @@ ICONS_TEMPLATE_C_FRAME = "const uint8_t {name}[] = {data};\n"
|
||||
ICONS_TEMPLATE_C_DATA = "const uint8_t* const {name}[] = {data};\n"
|
||||
ICONS_TEMPLATE_C_ICONS = "const Icon {name} = {{.width={width},.height={height},.frame_count={frame_count},.frame_rate={frame_rate},.frames=_{name}}};\n"
|
||||
|
||||
valid_dirs = list()
|
||||
# This will not stay, dont worry! This is temp code until we got time to rewrite this all
|
||||
we_are_here = "\\".join(os.path.abspath(__file__).split("\\")[:-2])
|
||||
dolphin_external = os.path.join(we_are_here, r"assets\dolphin\external/")
|
||||
potential_directories = [d for d in os.listdir(dolphin_external) if os.path.isdir(os.path.join(dolphin_external, d))] # Get all animation directories
|
||||
|
||||
for i in potential_directories: # loop through all of them
|
||||
if os.path.exists(os.path.join(dolphin_external, f"{i}\manifest.txt")): # check if they contain a manifest.txt TODO: This code should be moved to wherever manifest.txt files are validated!
|
||||
valid_dirs.append(os.path.join(dolphin_external, f"{i}")) # append valid directory to list
|
||||
|
||||
class Main(App):
|
||||
def init(self):
|
||||
@@ -246,6 +257,14 @@ class Main(App):
|
||||
else:
|
||||
self.logger.info("Manifest is up-to-date!")
|
||||
|
||||
# This will not stay, dont worry! This is temp code until we got time to rewrite this all
|
||||
global valid_dirs # access our global variable
|
||||
for i in valid_dirs: # We can copy the manifest for all of the valid dirs!
|
||||
i = i.split("/")[-1]
|
||||
print(f"assets\dolphin\external\{i}\manifest.txt")
|
||||
shutil.copyfile(fr"assets\dolphin\external\{i}\manifest.txt", fr"assets\resources\dolphin\{i}\manifest.txt")
|
||||
os.remove(r"assets\resources\dolphin\manifest.txt")
|
||||
|
||||
self.logger.info(f"Complete")
|
||||
|
||||
return 0
|
||||
@@ -274,10 +293,11 @@ class Main(App):
|
||||
self.logger.info(f"Processing Dolphin sources")
|
||||
dolphin = Dolphin()
|
||||
self.logger.info(f"Loading data")
|
||||
dolphin.load(self.args.input_directory)
|
||||
dolphin.load(valid_dirs)
|
||||
self.logger.info(f"Packing")
|
||||
dolphin.pack(self.args.output_directory, self.args.symbol_name)
|
||||
self.logger.info(f"Complete")
|
||||
__import__("time").sleep(2)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
@@ -257,48 +257,54 @@ class DolphinManifest:
|
||||
self.animations = []
|
||||
self.logger = logging.getLogger("DolphinManifest")
|
||||
|
||||
def load(self, source_directory: str):
|
||||
for i in ["sfw", "nsfw"]:
|
||||
manifest_filename = os.path.join(source_directory, f"{i}/manifest.txt")
|
||||
def load(self, loc: str):
|
||||
manifest_filename = os.path.join(loc, "manifest.txt")
|
||||
|
||||
file = FlipperFormatFile()
|
||||
file.load(manifest_filename)
|
||||
file = FlipperFormatFile()
|
||||
file.load(manifest_filename)
|
||||
|
||||
# Check file header
|
||||
filetype, version = file.getHeader()
|
||||
assert filetype == self.FILE_TYPE
|
||||
assert version == self.FILE_VERSION
|
||||
# Check file header
|
||||
filetype, version = file.getHeader()
|
||||
assert filetype == self.FILE_TYPE
|
||||
assert version == self.FILE_VERSION
|
||||
|
||||
# Load animation data
|
||||
while True:
|
||||
try:
|
||||
# Read animation spcification
|
||||
name = file.readKey("Name")
|
||||
min_butthurt = file.readKeyInt("Min butthurt")
|
||||
max_butthurt = file.readKeyInt("Max butthurt")
|
||||
min_level = file.readKeyInt("Min level")
|
||||
max_level = file.readKeyInt("Max level")
|
||||
weight = file.readKeyInt("Weight")
|
||||
# Load animation data
|
||||
while True:
|
||||
try:
|
||||
# Read animation spcification
|
||||
name = file.readKey("Name")
|
||||
min_butthurt = file.readKeyInt("Min butthurt")
|
||||
max_butthurt = file.readKeyInt("Max butthurt")
|
||||
min_level = file.readKeyInt("Min level")
|
||||
max_level = file.readKeyInt("Max level")
|
||||
weight = file.readKeyInt("Weight")
|
||||
|
||||
assert len(name) > 0
|
||||
assert min_butthurt >= 0
|
||||
assert max_butthurt >= 0 and max_butthurt >= min_butthurt
|
||||
assert min_level >= 0
|
||||
assert max_level >= 0 and max_level >= min_level
|
||||
assert weight >= 0
|
||||
assert len(name) > 0
|
||||
assert min_butthurt >= 0
|
||||
assert max_butthurt >= 0 and max_butthurt >= min_butthurt
|
||||
assert min_level >= 0
|
||||
assert max_level >= 0 and max_level >= min_level
|
||||
assert weight >= 0
|
||||
|
||||
# Initialize animation
|
||||
animation = DolphinBubbleAnimation(
|
||||
name, min_butthurt, max_butthurt, min_level, max_level, weight
|
||||
)
|
||||
# Initialize animation
|
||||
animation = DolphinBubbleAnimation(
|
||||
name, min_butthurt, max_butthurt, min_level, max_level, weight
|
||||
)
|
||||
|
||||
# Load Animation meta and frames
|
||||
animation.load(os.path.join(source_directory, name))
|
||||
# Load Animation meta and frames
|
||||
|
||||
# Add to array
|
||||
self.animations.append(animation)
|
||||
except EOFError:
|
||||
break
|
||||
# handle both slash types bc we can
|
||||
newname = name.split("\\")
|
||||
if len(newname) < 2:
|
||||
newname = name.split("/")
|
||||
|
||||
newname = str(newname[1])
|
||||
animation.load(os.path.join(loc, newname))
|
||||
|
||||
# Add to array
|
||||
self.animations.append(animation)
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
def _renderTemplate(self, template_filename: str, output_filename: str, **kwargs):
|
||||
template = Templite(filename=template_filename)
|
||||
@@ -362,11 +368,12 @@ class Dolphin:
|
||||
self.manifest = DolphinManifest()
|
||||
self.logger = logging.getLogger("Dolphin")
|
||||
|
||||
def load(self, source_directory: str):
|
||||
assert os.path.isdir(source_directory)
|
||||
# Load Manifest
|
||||
self.logger.info(f"Loading directory {source_directory}")
|
||||
self.manifest.load(source_directory)
|
||||
def load(self, valid_dirs: list):
|
||||
for loc in valid_dirs:
|
||||
assert os.path.isdir(loc)
|
||||
# Load Manifest
|
||||
self.logger.info(f"Loading directory {loc}")
|
||||
self.manifest.load(loc)
|
||||
|
||||
def pack(self, output_directory: str, symbol_name: str = None):
|
||||
self.manifest.save(output_directory, symbol_name)
|
||||
|
||||
Reference in New Issue
Block a user