Skip to content

Commit

Permalink
tech panel
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisCris committed Feb 7, 2025
1 parent a2d7497 commit 2923317
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
25 changes: 12 additions & 13 deletions frontend/palworld-pal-editor-webui/src/components/PlayerEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const isMinLv = () => {
{{ palStore.getTranslatedText("Editor_IV") }}
</p>
</div>
<div class="EditorItem flex-h">
<div class="EditorItem flex-h maxW">
<div class="levels-container">
<div class="level-row" v-for="(items, level) in palStore.TECH_LV_DICT" :key="level">
<div class="level-indicator">
Expand All @@ -70,10 +70,6 @@ const isMinLv = () => {
gap: .5rem;
}
.PalEditor.unref {
filter: grayscale(100%);
}
.EditorItem {
display: flex;
flex-shrink: 0;
Expand All @@ -82,10 +78,15 @@ const isMinLv = () => {
border-radius: 1rem;
}
.EditorItem.maxW {
padding: 1rem;
max-width: var(--editor-panel-width);
}
div.editField {
/* border-style: dashed;
border-width: 1px;
border-color: white; */
border-width: 1px;
border-color: white; */
/* width: 100%; */
/* flex-wrap: nowrap; */
gap: 5px
Expand All @@ -94,7 +95,7 @@ div.editField {
div.basicInfo {
position: relative;
max-width: calc(var(--editor-panel-width) - 380px);
min-width: 600px;
/* min-width: calc(max(100%,var(--editor-panel-width))); */
}
hr {
Expand Down Expand Up @@ -297,20 +298,18 @@ select.selector {
.levels-container {
display: flex;
/* Use Flexbox */
flex-direction: column;
/* Stack each row vertically */
max-height: 80vh;
/* limit vertical space */
overflow-y: auto;
/* scroll vertically if needed */
max-width: 100%;
padding: 8px;
justify-content: flex-start;
justify-content:left;
}
.level-row {
display: flex;
align-items: center;
max-width: 100%;
}
.level-indicator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<script setup>
import { ref, computed } from 'vue'
import { usePalEditorStore } from '@/stores/paleditor'
const palStore = usePalEditorStore()
const props = defineProps({
item: {
Expand All @@ -16,10 +18,8 @@ const props = defineProps({
}
})
const isLocked = ref(false)
function toggleLock() {
isLocked.value = !isLocked.value
palStore.SELECTED_PLAYER_DATA.toggleTech(props.item.InternalName, isLocked.value)
}
const bgStyle = computed(() => {
Expand All @@ -32,6 +32,11 @@ const bgStyle = computed(() => {
backgroundImage: `url('/image/${cat}/${internalName}')`
}
})
const isLocked = computed(() => {
return !palStore.SELECTED_PLAYER_DATA.UnlockedRecipeTechnologyNames.includes(props.item.InternalName)
})
</script>

<style scoped>
Expand Down
14 changes: 14 additions & 0 deletions frontend/palworld-pal-editor-webui/src/stores/paleditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const usePalEditorStore = defineStore("paleditor", () => {
this.OtomoCharacterContainerId = obj.OtomoCharacterContainerId;
this.PalStorageContainerId = obj.PalStorageContainerId;
this.pals = new Map();
this.UnlockedRecipeTechnologyNames = obj.UnlockedRecipeTechnologyNames;
}

levelDown() {
Expand All @@ -41,6 +42,19 @@ export const usePalEditorStore = defineStore("paleditor", () => {
: MAX_INVALID_LEVEL;
updatePlayer({ target: { name: "Level", value: this.Level } });
}

toggleTech(tech, status) {
updatePlayer({
target: {
name: "toggle_UnlockedRecipeTechnologyNames",
value: {
tech: tech,
status: status,
},
},
});

}
}

class PalData {
Expand Down
16 changes: 10 additions & 6 deletions src/palworld_pal_editor/api/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ def get_player_list():
0,
{
"players": [
player_to_dict(player)
for player in SaveManager().get_players()
player_to_dict(player) for player in SaveManager().get_players()
],
"hasWorkingPal": (True if len(workingpals) else False),
},
Expand All @@ -95,11 +94,13 @@ def get_player_data():
LOGGER.warning(f"Player {PlayerUId} not exist")
return reply(1, None, f"Player {PlayerUId} not exist")

return reply(
0,
player_to_dict(player_entity),
player_dict = player_to_dict(player_entity)
player_dict["UnlockedRecipeTechnologyNames"] = (
player_entity.UnlockedRecipeTechnologyNames or []
)

return reply(0, player_dict)


def player_to_dict(player: PlayerEntity):
return {
Expand All @@ -109,6 +110,7 @@ def player_to_dict(player: PlayerEntity):
"HasViewingCage": player.has_viewing_cage(),
"OtomoCharacterContainerId": str(player.OtomoCharacterContainerId),
"PalStorageContainerId": str(player.PalStorageContainerId),
"UnlockedRecipeTechnologyNames": [],
}


Expand All @@ -130,13 +132,15 @@ def patch_player_data():

try:
match key:
case "toggle_UnlockedRecipeTechnologyNames":
player_entity.toggle_UnlockedRecipeTechnologyNames(value["tech"], value["status"])
case "unlock_viewing_cage":
player_entity.unlock_viewing_cage()
case _:
if isinstance(err := setattr(player_entity, key, value), TypeError):
return reply(1, None, f"Error in patch_player_data {err}")
except Exception as e:
stack_trace = traceback.format_exc()
LOGGER.error(f"Error in patching player data {stack_trace}")
LOGGER.error(f"Error in patching player data {stack_trace}, key: {key}, value: {value}")
return reply(1, None, f"Error in patching player data {stack_trace}")
return reply(0)
20 changes: 12 additions & 8 deletions src/palworld_pal_editor/core/player_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,29 @@ def UnlockedRecipeTechnologyNames(self) -> Optional[list[str]]:
)

@LOGGER.change_logger("UnlockedRecipeTechnologyNames")
def add_UnlockedRecipeTechnologyNames(self, tech: str) -> bool:
def toggle_UnlockedRecipeTechnologyNames(self, tech: str, status: bool):
if self.UnlockedRecipeTechnologyNames is None:
self._player_save_data["UnlockedRecipeTechnologyNames"] = (
PalObjects.ArrayProperty("NameProperty", {"values": []})
)

if tech in self.UnlockedRecipeTechnologyNames:
LOGGER.warning(f"{self} has already been unlocked, skipping")
return False

self.UnlockedRecipeTechnologyNames.append(tech)
if status:
if tech in self.UnlockedRecipeTechnologyNames:
LOGGER.warning(f"Attempt to unlock {self}, but it has already been unlocked, skipping")
return
self.UnlockedRecipeTechnologyNames.append(tech)
else:
if tech not in self.UnlockedRecipeTechnologyNames:
LOGGER.warning(f"Attempt to lock {self}, but it has not been unlocked, skipping")
return
self.UnlockedRecipeTechnologyNames.remove(tech)

def has_viewing_cage(self) -> bool:
if not self.UnlockedRecipeTechnologyNames:
return False
return "DisplayCharacter" in self.UnlockedRecipeTechnologyNames

def unlock_viewing_cage(self):
self.add_UnlockedRecipeTechnologyNames("DisplayCharacter")
self.toggle_UnlockedRecipeTechnologyNames("DisplayCharacter", True)

@property
def PlayerGVAS(self) -> Optional[tuple[GvasFile, int]]:
Expand Down
1 change: 1 addition & 0 deletions src/palworld_pal_editor/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def _print_change(self, entity, val_name, old_val, new_val):
self.info(f"{entity} | {val_name}: Added {added}")
if removed:
self.info(f"{entity} | {val_name}: Removed {removed}")
return
self.info(f"{entity} | {val_name}: {old_val} -> {new_val}")

def debug(self, message: str):
Expand Down

0 comments on commit 2923317

Please sign in to comment.