| 53 | return sha256(self.data).hexdigest() |
| 54 | |
| 55 | class Asset(base.SpriteSubComponent): |
| 56 | def __init__(self, |
| 57 | name: str = "costume1", |
| 58 | file_name: str = "b7853f557e4426412e64bb3da6531a99.svg", |
| 59 | _sprite: commons.SpriteInput = build_defaulting.SPRITE_DEFAULT): |
| 60 | """ |
| 61 | Represents a generic asset, with metadata. Can be a sound or a costume. |
| 62 | https://en.scratch-wiki.info/wiki/Scratch_File_Format#Assets |
| 63 | """ |
| 64 | try: |
| 65 | asset_id, data_format = file_name.split('.') |
| 66 | except ValueError: |
| 67 | raise ValueError(f"Invalid file name: {file_name}, # of '.' in {file_name} ({file_name.count('.')}) != 2; " |
| 68 | f"(too many/few values to unpack)") |
| 69 | self.name = name |
| 70 | |
| 71 | self.id = asset_id |
| 72 | self.data_format = data_format |
| 73 | |
| 74 | super().__init__(_sprite) |
| 75 | |
| 76 | def __repr__(self): |
| 77 | return f"Asset<{self.name!r}>" |
| 78 | |
| 79 | @property |
| 80 | def folder(self): |
| 81 | """ |
| 82 | Get the folder name of this asset, based on the asset name. Uses the TurboWarp syntax |
| 83 | """ |
| 84 | return commons.get_folder_name(self.name) |
| 85 | |
| 86 | @property |
| 87 | def name_nfldr(self): |
| 88 | """ |
| 89 | Get the asset name after removing the folder name. Uses the TurboWarp syntax |
| 90 | """ |
| 91 | return commons.get_name_nofldr(self.name) |
| 92 | |
| 93 | @property |
| 94 | def file_name(self): |
| 95 | """ |
| 96 | Get the exact file name, as it would be within an sb3 file |
| 97 | equivalent to the md5ext value using in scratch project JSON |
| 98 | """ |
| 99 | return f"{self.id}.{self.data_format}" |
| 100 | |
| 101 | @property |
| 102 | def md5ext(self): |
| 103 | """ |
| 104 | Get the exact file name, as it would be within an sb3 file |
| 105 | equivalent to the md5ext value using in scratch project JSON |
| 106 | |
| 107 | (alias for file_name) |
| 108 | """ |
| 109 | return self.file_name |
| 110 | |
| 111 | @property |
| 112 | def parent(self): |