Skip to content

Commit

Permalink
only save path picker result if ok is clicked & hint pal folder
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisCris committed Apr 26, 2024
1 parent 32017f5 commit 118ef99
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
33 changes: 22 additions & 11 deletions frontend/palworld-pal-editor-webui/src/components/PathPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const sortedPathChildren = computed(() => {
})
})
const savePickerResult = () => {
palStore.SHOW_FILE_PICKER = false
palStore.PAL_GAME_SAVE_PATH = palStore.PAL_FILE_PICKER_PATH
}
// const scrollElement = ref(null);
// const checkScroll = () => {
Expand All @@ -43,19 +49,22 @@ const sortedPathChildren = computed(() => {
<template>
<div class="popup">
<div class="currentPath">
<IconButton icon="⤴️" @click="palStore.path_back"/>
<InputArea v-model="palStore.PAL_GAME_SAVE_PATH"/>
<IconButton icon="➡️" @click="palStore.update_picker_result(palStore.PAL_GAME_SAVE_PATH)"/>
<IconButton icon="⤴️" @click="palStore.path_back" />
<InputArea v-model="palStore.PAL_FILE_PICKER_PATH" />
<IconButton icon="➡️" @click="palStore.update_picker_result(palStore.PAL_FILE_PICKER_PATH)" />
</div>

<ul ref="scrollElement">
<li v-for="([key, value], index) of sortedPathChildren" :key="index" :isdir="value.isDir"
@click="palStore.update_picker_result(key)" :fullpath="key">
<li v-for="([key, value], index) of sortedPathChildren"
:key="index"
:isdir="value.isDir"
@click="() => { if (value.isDir) palStore.update_picker_result(key) }"
:fullpath="key"
>
{{ value.isDir ? "📁" : "📄" }} {{ value.filename }}
</li>
</ul>

<BarButton @click="palStore.SHOW_FILE_PICKER = false" content="OK"/>
<BarButton @click="savePickerResult" content="OK" :disabled="!palStore.IS_PAL_SAVE_PATH" />
</div>
</template>

Expand Down Expand Up @@ -95,16 +104,18 @@ const sortedPathChildren = computed(() => {
flex: 1;
}
.popup li[isdir=true] {
cursor: pointer;
}
.popup li {
margin: .2rem .2rem;
padding: .3rem .3rem;
border-radius: 0.5rem;
color: whitesmoke;
cursor: pointer;
}
.popup li:hover {
.popup li:hover[isdir=true] {
background-color: #4b8d5e;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ button:hover {
button:disabled {
background-color: #8a8a8a;
cursor: auto;
}
</style>
10 changes: 9 additions & 1 deletion frontend/palworld-pal-editor-webui/src/stores/paleditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ export const usePalEditorStore = defineStore("paleditor", () => {

const PAL_LIST_SEARCH_KEYWORD = ref("")

const IS_PAL_SAVE_PATH = ref(false)

// data
const BASE_PAL_MAP = ref(new Map());
const PLAYER_MAP = ref(new Map());
Expand All @@ -277,7 +279,9 @@ export const usePalEditorStore = defineStore("paleditor", () => {
const HAS_PASSWORD = ref(false);
const PAL_WRITE_BACK_PATH = ref("");
const PATH_CONTEXT = ref(new Map())

const SHOW_FILE_PICKER = ref(false)
const PAL_FILE_PICKER_PATH = ref(PAL_GAME_SAVE_PATH.value)

// auth
let auth_token = "";
Expand Down Expand Up @@ -452,7 +456,8 @@ export const usePalEditorStore = defineStore("paleditor", () => {
}

function update_path_picker_result(data) {
PAL_GAME_SAVE_PATH.value = data.currentPath
IS_PAL_SAVE_PATH.value = data.isPalDir
PAL_FILE_PICKER_PATH.value = data.currentPath
PATH_CONTEXT.value = new Map(Object.entries(data.children))
SHOW_FILE_PICKER.value = true
}
Expand Down Expand Up @@ -1258,6 +1263,9 @@ export const usePalEditorStore = defineStore("paleditor", () => {

PATH_CONTEXT,
SHOW_FILE_PICKER,
PAL_FILE_PICKER_PATH,
IS_PAL_SAVE_PATH,

HAS_WORKING_PAL_FLAG,
BASE_PAL_BTN_CLK_FLAG,
PAL_GAME_SAVE_PATH,
Expand Down
9 changes: 6 additions & 3 deletions src/palworld_pal_editor/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def reply(status, data=None, msg=None):


def get_path_context(path: Path) -> dict:
current_path = path.resolve()

current_path = path.resolve()
children = {
str(child.resolve()): {
"filename": child.name,
Expand All @@ -24,9 +23,13 @@ def get_path_context(path: Path) -> dict:
for child in sorted(current_path.iterdir(), key=lambda x: (x.is_file(), x.name))
}

names = [child.name for child in current_path.iterdir()]
is_pal_dir = "Level.sav" in names and "Players" in names

return {
"currentPath": str(current_path),
"children": children
"children": children,
"isPalDir": is_pal_dir
}


Expand Down

0 comments on commit 118ef99

Please sign in to comment.