Skip to content

Commit

Permalink
PalWorld 0.3.9 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisCris committed Oct 7, 2024
1 parent d99eee3 commit 5b5929b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"--mode=web",
"--lang=zh-CN",
"--debug"
]
],
"justMyCode": false
}
]
}
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN cd "/app/frontend/palworld-pal-editor-webui" \
&& mv "/app/frontend/palworld-pal-editor-webui/dist" "/app/src/palworld_pal_editor/webui"

RUN pip install --no-cache-dir -r requirements.txt \
pip install -e .
&& pip install -e .

RUN chmod +x /app/docker/app.sh

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ keywords = ["palworld", "editor", "pal"]
license = {file = "LICENSE"}
requires-python = ">=3.11"
readme = "README.md"
version = "0.9.0"
version = "0.10.0"
dependencies = [
"setuptools==69.1.0",
"palworld_save_tools==0.23.1",
"palworld_save_tools==0.24.0",
"wheel==0.42.0",
"Flask==3.0.2",
"pyinstaller==6.4.0",
Expand All @@ -36,4 +36,4 @@ Homepage = "https://github.com/KrisCris/Palworld-Pal-Editor"
Documentation = "https://github.com/KrisCris/Palworld-Pal-Editor"
Repository = "https://github.com/KrisCris/Palworld-Pal-Editor.git"
Issues = "https://github.com/KrisCris/Palworld-Pal-Editor/issues"
Changelog = "https://github.com/KrisCris/Palworld-Pal-Editor"
Changelog = "https://github.com/KrisCris/Palworld-Pal-Editor"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
setuptools==69.1.0
palworld_save_tools==0.23.1
palworld_save_tools==0.24.0
wheel==0.42.0
Flask==3.0.2
pyinstaller==6.4.0
Expand Down
35 changes: 24 additions & 11 deletions src/palworld_pal_editor/core/group_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,41 @@ def __init__(self, group_obj: dict):
def __str__(self) -> str:
lines = []
lines.append(f"{self.guild_name} - {self.group_id}")
for player in self.players:
for player in self.players if self.players else []:
lines.append(f"\n\t{str(player[0])} - {str(player[1])}")
return "\t".join(lines)

def add_pal(self, instanceId: UUID | str) -> bool:
if self.has_pal(instanceId):
LOGGER.warning("Pal ID already exists")
return False

new_handle = PalObjects.individual_character_handle_id(instanceId)
self.instance_map[str(instanceId)] = new_handle
if self.individual_character_handle_ids is None:
self._group_param["individual_character_handle_ids"] = []
self.individual_character_handle_ids.append(new_handle)
match self.individual_character_handle_ids:
case None:
self._group_param["individual_character_handle_ids"] = [new_handle]
case _:
self.individual_character_handle_ids.append(new_handle)
# if self.individual_character_handle_ids is None:
# self._group_param["individual_character_handle_ids"] = []
# self.individual_character_handle_ids.append(new_handle)
return True

def del_pal(self, instanceId: UUID | str):
if not self.has_pal(instanceId):
LOGGER.warning(f"Pal {instanceId} not exist in group {self.guild_name}")
return
handle = self.instance_map.pop(instanceId)
self.individual_character_handle_ids.remove(handle)
match self.individual_character_handle_ids:
case None:
pass
case _:
self.individual_character_handle_ids.remove(handle)

def has_pal(self, instanceId: UUID | str) -> bool:
return instanceId in self.instance_map

def has_player(self, playerUId: UUID | str) -> bool:
return playerUId in self.player_map

Expand All @@ -72,7 +81,10 @@ def guild_name(self) -> Optional[str]:

@property
def players(self) -> Optional[list[tuple[UUID, str]]]:
return [(player_data['player_uid'], player_data['player_info']['player_name']) for player_data in self._group_param.get("players")]
return [
(player_data["player_uid"], player_data["player_info"]["player_name"])
for player_data in self._group_param.get("players") or []
]


class GroupData:
Expand Down Expand Up @@ -108,9 +120,10 @@ def get_group(self, group_id: UUID | str) -> Optional[PalGroup]:
return self.group_map.get(group_id)

def get_groups(self) -> list[PalGroup]:
return self.group_map.values()
return list(self.group_map.values())

def get_player_group_id(self, player_uid: UUID | str) -> Optional[UUID]:
for group in self.get_groups():
if group.has_player(player_uid):
return group.group_id
return None
20 changes: 10 additions & 10 deletions src/palworld_pal_editor/core/pal_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,17 @@ def NickName(self, value: str) -> None:

@property
def Level(self) -> Optional[int]:
return PalObjects.get_BaseType(self._pal_param.get("Level"))
return PalObjects.get_ByteProperty(self._pal_param.get("Level"))

@Level.setter
@LOGGER.change_logger('Level')
@type_guard
def Level(self, value: int) -> None:
value = clamp(1, 55, value)
if self.Level is None:
self._pal_param["Level"] = PalObjects.IntProperty(value)
self._pal_param["Level"] = PalObjects.ByteProperty(value)
else:
self._pal_param["Level"]["value"] = value
PalObjects.set_ByteProperty(self._pal_param['Level'], value)
self.Exp = DataProvider.get_level_xp(self.Level)

if maxHP := self.ComputedMaxHP:
Expand All @@ -398,7 +398,7 @@ def Exp(self, value: int) -> None:
if self.Exp is None:
self._pal_param["Exp"] = PalObjects.IntProperty(value)
else:
self._pal_param["Exp"]["value"] = value
PalObjects.set_BaseType(self._pal_param['Exp'], value)

@property
def Rank(self) -> Optional[PalRank]:
Expand Down Expand Up @@ -687,19 +687,19 @@ def pop_MasteredWaza(self, idx: int = None, item: str = None) -> Optional[str]:

@property
def Talent_HP(self) -> Optional[int]:
return PalObjects.get_BaseType(self._pal_param.get('Talent_HP'))
return PalObjects.get_ByteProperty(self._pal_param.get('Talent_HP'))

@property
def Talent_Melee(self) -> Optional[int]:
return PalObjects.get_BaseType(self._pal_param.get('Talent_Melee'))
return PalObjects.get_ByteProperty(self._pal_param.get('Talent_Melee'))

@property
def Talent_Shot(self) -> Optional[int]:
return PalObjects.get_BaseType(self._pal_param.get('Talent_Shot'))
return PalObjects.get_ByteProperty(self._pal_param.get('Talent_Shot'))

@property
def Talent_Defense(self) -> Optional[int]:
return PalObjects.get_BaseType(self._pal_param.get('Talent_Defense'))
return PalObjects.get_ByteProperty(self._pal_param.get('Talent_Defense'))

@Talent_HP.setter
@LOGGER.change_logger("Talent_HP")
Expand Down Expand Up @@ -968,9 +968,9 @@ def _set_soul_rank(self, property_name: str, rank: int):
def _set_iv(self, property_name: str, value: int):
iv = clamp(0, 100, value)
if getattr(self, property_name) is None:
self._pal_param[property_name] = PalObjects.IntProperty(iv)
self._pal_param[property_name] = PalObjects.ByteProperty(iv)
else:
PalObjects.set_BaseType(self._pal_param[property_name], iv)
PalObjects.set_ByteProperty(self._pal_param[property_name], iv)

def _get_display_name(self) -> str:
cache_key = (Config.i18n, self.DataAccessKey, self.NickName, self.IsRarePal, self.IsBOSS, self.IsTower, self.Gender)
Expand Down
15 changes: 15 additions & 0 deletions src/palworld_pal_editor/core/pal_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ def FloatProperty(value: float):
@staticmethod
def BoolProperty(value: bool):
return {"value": value, "id": None, "type": "BoolProperty"}

@staticmethod
def ByteProperty(value: Any, type: str = None):
return {"value": {
"type": type,
"value": value
}, "id": None, "type": "ByteProperty"}

@staticmethod
def get_BaseType(container: dict) -> Optional[Any]:
Expand All @@ -121,6 +128,14 @@ def get_BaseType(container: dict) -> Optional[Any]:
def set_BaseType(container: dict, value: Any):
container["value"] = value

@staticmethod
def get_ByteProperty(container: dict) -> Optional[Any]:
return get_nested_attr(container, ["value", "value"])

@staticmethod
def set_ByteProperty(container: dict, value: Any):
container["value"]["value"] = value

@staticmethod
def Guid(value: str | UUID):
return {
Expand Down

0 comments on commit 5b5929b

Please sign in to comment.