Skip to content

Commit

Permalink
Add particle support
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLich committed Nov 11, 2021
1 parent 613fa11 commit 9024a9c
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
45 changes: 45 additions & 0 deletions generation/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
}
],
"json_resources": [
{
"class": "ParticleFileRP",
"name": "particles",
"file_path": "particles",
"getter": {
"name": "get_particle",
"property": "identifier"
}
},
{
"class": "AttachableFileRP",
"name": "attachables",
Expand Down Expand Up @@ -166,6 +175,39 @@
}
],
"json_resources": [
{
"class": "ParticleFileRP",
"properties": [
{
"name": "format_version",
"json_path": "format_version"
},
{
"name": "identifier",
"json_path": "particle_effect/description/identifier"
}
],
"sub_resources": [
{
"json_path": "particle_effect/components/*",
"class": "GenericSubResource",
"getter": {
"name": "get_component",
"property": "id"
},
"name": "components"
},
{
"json_path": "particle_effect/events/*",
"class": "GenericSubResource",
"getter": {
"name": "get_event",
"property": "id"
},
"name": "events"
}
]
},
{
"class": "AttachableFileRP",
"properties": [
Expand Down Expand Up @@ -488,6 +530,9 @@
}
]
},
{
"class": "GenericSubResource"
},
{
"class": "Cube"
}
Expand Down
77 changes: 77 additions & 0 deletions reticulator/reticulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ class ResourcePack(Pack): pass
class ResourcePack(Pack):
def __init__(self, input_path: str, project: Project = None):
super().__init__(input_path, project=project)
self.__particles = []
self.__attachables = []
self.__animation_controller_files = []
self.__animation_files = []
Expand All @@ -774,6 +775,15 @@ def __init__(self, input_path: str, project: Project = None):
self.__items = []


@cached_property
def particles(self) -> list[ParticleFileRP]:
base_directory = os.path.join(self.input_path, "particles")
for local_path in glob.glob(base_directory + "/**/*.json", recursive=True):
local_path = os.path.relpath(local_path, self.input_path)
self.__particles.append(ParticleFileRP(file_path = local_path, pack = self))

return self.__particles

@cached_property
def attachables(self) -> list[AttachableFileRP]:
base_directory = os.path.join(self.input_path, "attachables")
Expand Down Expand Up @@ -863,6 +873,12 @@ def models(self) -> list[Model]:
return children


def get_particle(self, identifier:str) -> ParticleFileRP:
for child in self.particles:
if child.identifier == identifier:
return child
raise AssetNotFoundError(identifier)

def get_attachable(self, identifier:str) -> AttachableFileRP:
for child in self.attachables:
if child.identifier == identifier:
Expand Down Expand Up @@ -1051,6 +1067,57 @@ def get_block(self, identifier:str) -> BlockFileBP:



class ParticleFileRP(JsonFileResource):
def __init__(self, data: dict = None, file_path: str = None, pack: Pack = None) -> None:
super().__init__(data = data, file_path = file_path, pack = pack)
self.__components = []
self.__events = []


@property
def format_version(self):
return self.get_jsonpath("format_version")

@format_version.setter
def format_version(self, format_version):
return self.set_jsonpath("format_version", format_version)

@property
def identifier(self):
return self.get_jsonpath("particle_effect/description/identifier")

@identifier.setter
def identifier(self, identifier):
return self.set_jsonpath("particle_effect/description/identifier", identifier)


@cached_property
def components(self) -> list[GenericSubResource]:
for path, data in self.get_data_at("particle_effect/components/*"):
self.__components.append(GenericSubResource(parent = self, json_path = path, data = data))
return self.__components

@cached_property
def events(self) -> list[GenericSubResource]:
for path, data in self.get_data_at("particle_effect/events/*"):
self.__events.append(GenericSubResource(parent = self, json_path = path, data = data))
return self.__events


def get_component(self, id:str) -> GenericSubResource:
for child in self.components:
if child.id == id:
return child
raise AssetNotFoundError(id)

def get_event(self, id:str) -> GenericSubResource:
for child in self.events:
if child.id == id:
return child
raise AssetNotFoundError(id)



class AttachableFileRP(JsonFileResource):
def __init__(self, data: dict = None, file_path: str = None, pack: Pack = None) -> None:
super().__init__(data = data, file_path = file_path, pack = pack)
Expand Down Expand Up @@ -1590,6 +1657,16 @@ def cubes(self) -> list[Cube]:



class GenericSubResource(JsonSubResource):
def __init__(self, data: dict = None, parent: Resource = None, json_path: str = None ) -> None:
super().__init__(data=data, parent=parent, json_path=json_path)







class Cube(JsonSubResource):
def __init__(self, data: dict = None, parent: Resource = None, json_path: str = None ) -> None:
super().__init__(data=data, parent=parent, json_path=json_path)
Expand Down

0 comments on commit 9024a9c

Please sign in to comment.