Skip to content

Commit

Permalink
Add USIEngineMergeDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfish-shogi committed Oct 20, 2024
1 parent ea726b7 commit abace1a
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/common/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ export const en: Texts = {
noEngineRegistered: "No engine",
duplicate: "Copy",
add: "Add",
compareAndMerge: "Compare & Merge",
compareEngineSettings: "Compare Engine Settings",
noDifference: "No Difference",
mergeToLeft: "Merge to Left",
mergeToRight: "Merge to Right",
recommended: "Recommended",
import: "Import",
saveAndClose: "Save & Close",
Expand Down Expand Up @@ -496,6 +501,8 @@ export const en: Texts = {
beginner: "Beginner",
staticRook: "Static Rook",
rangingRook: "Ranging Rook",
pleaseSelectEngines: "Please select engines.",
thisItemCannotBeMerged: "This item cannot be merged.",
tryingToConnectAndLoginToCSAServer: "Trying to connect and login to CSA server.",
inBrowserLogsOutputToConsoleAndIgnoreThisSetting:
"*In web browser version, it will output logs to console and ignore this setting.",
Expand Down
7 changes: 7 additions & 0 deletions src/common/i18n/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ export const ja: Texts = {
noEngineRegistered: "エンジンが登録されていません。",
duplicate: "複製",
add: "追加",
compareAndMerge: "比較・マージ",
compareEngineSettings: "エンジン設定の比較",
noDifference: "差分なし",
mergeToLeft: "左へマージ",
mergeToRight: "右へマージ",
recommended: "推奨",
import: "取り込む",
saveAndClose: "保存して閉じる",
Expand Down Expand Up @@ -496,6 +501,8 @@ export const ja: Texts = {
beginner: "初心者",
staticRook: "居飛車",
rangingRook: "振り飛車",
pleaseSelectEngines: "エンジンを選択してください。",
thisItemCannotBeMerged: "この項目はマージできません。",
tryingToConnectAndLoginToCSAServer: "CSAサーバーへの接続とログインを試みています。",
inBrowserLogsOutputToConsoleAndIgnoreThisSetting:
"※ブラウザ版ではログがコンソールに出力され、ここでの設定は無視されます。",
Expand Down
7 changes: 7 additions & 0 deletions src/common/i18n/locales/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ export const vi: Texts = {
noEngineRegistered: "Không có phần mềm",
duplicate: "Sao chép",
add: "Thêm",
compareAndMerge: "比較・マージ", // TODO: translate
compareEngineSettings: "エンジン設定の比較", // TODO: translate
noDifference: "差分なし", // TODO: translate
mergeToLeft: "左へマージ", // TODO: translate
mergeToRight: "右へマージ", // TODO: translate
recommended: "Đề xuất",
import: "Nhập",
saveAndClose: "Lưu và đóng",
Expand Down Expand Up @@ -496,6 +501,8 @@ export const vi: Texts = {
beginner: "初心者", // TODO: translate
staticRook: "居飛車", // TODO: translate
rangingRook: "振り飛車", // TODO: translate
pleaseSelectEngines: "エンジンを選択してください。", // TODO: translate
thisItemCannotBeMerged: "この項目はマージできません。", // TODO: translate
tryingToConnectAndLoginToCSAServer: "Đang kết nối và đăng nhập vào máy chủ CSA.",
inBrowserLogsOutputToConsoleAndIgnoreThisSetting:
"*Bản trình duyệt sẽ xuất log ra trình nhắc lệnh và bỏ qua cài đặt này.",
Expand Down
7 changes: 7 additions & 0 deletions src/common/i18n/locales/zh_tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ export const zh_tw: Texts = {
noEngineRegistered: "尚未登錄引擎。",
duplicate: "複製",
add: "追加",
compareAndMerge: "比較・マージ", // TODO: translate
compareEngineSettings: "エンジン設定の比較", // TODO: translate
noDifference: "差分なし", // TODO: translate
mergeToLeft: "左へマージ", // TODO: translate
mergeToRight: "右へマージ", // TODO: translate
recommended: "推薦",
import: "匯入",
saveAndClose: "保存並關閉",
Expand Down Expand Up @@ -493,6 +498,8 @@ export const zh_tw: Texts = {
beginner: "初心者", // TODO: translate
staticRook: "居飛車", // TODO: translate
rangingRook: "振り飛車", // TODO: translate
pleaseSelectEngines: "エンジンを選択してください。", // TODO: translate
thisItemCannotBeMerged: "この項目はマージできません。", // TODO: translate
tryingToConnectAndLoginToCSAServer: "正在連接並登入CSA伺服器。",
inBrowserLogsOutputToConsoleAndIgnoreThisSetting:
"※在瀏覽器版本中紀錄會於 console 中顯示,並無視此處的設定。",
Expand Down
7 changes: 7 additions & 0 deletions src/common/i18n/text_template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ export type Texts = {
noEngineRegistered: string;
duplicate: string;
add: string;
compareAndMerge: string;
compareEngineSettings: string;
noDifference: string;
mergeToLeft: string;
mergeToRight: string;
recommended: string;
import: string;
saveAndClose: string;
Expand Down Expand Up @@ -491,6 +496,8 @@ export type Texts = {
beginner: string;
staticRook: string;
rangingRook: string;
pleaseSelectEngines: string;
thisItemCannotBeMerged: string;
tryingToConnectAndLoginToCSAServer: string;
inBrowserLogsOutputToConsoleAndIgnoreThisSetting: string;
shouldRestartToApplyLogSettings: string;
Expand Down
51 changes: 51 additions & 0 deletions src/common/settings/usi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,57 @@ function isValidOptionValue(option: USIEngineOption): boolean {
return true;
}

export type USIEngineOptionDiff = {
name: string;
leftValue: string | number | undefined;
rightValue: string | number | undefined;
mergeable: boolean;
};

export function compareUSIEngineOptions(left: USIEngine, right: USIEngine): USIEngineOptionDiff[] {
const result = [] as USIEngineOptionDiff[];
function append(leftOption?: USIEngineOption, rightOption?: USIEngineOption) {
const leftHasValue = leftOption && leftOption.type !== "button";
const rightHasValue = rightOption && rightOption.type !== "button";
if (leftHasValue && rightHasValue && leftOption.value !== rightOption.value) {
result.push({
name: leftOption.name,
leftValue: getUSIEngineOptionCurrentValue(leftOption),
rightValue: getUSIEngineOptionCurrentValue(rightOption),
mergeable: leftOption.type === rightOption.type,
});
} else if (leftHasValue && !rightHasValue) {
result.push({
name: leftOption.name,
leftValue: getUSIEngineOptionCurrentValue(leftOption),
rightValue: undefined,
mergeable: false,
});
} else if (!leftHasValue && rightHasValue) {
result.push({
name: rightOption.name,
leftValue: undefined,
rightValue: getUSIEngineOptionCurrentValue(rightOption),
mergeable: false,
});
}
}
function compareOrder(a: USIEngineOption, b: USIEngineOption): number {
return a.order < b.order ? -1 : 1;
}
for (const leftOption of Object.values(left.options).sort(compareOrder)) {
const rightOption = right.options[leftOption.name];
append(leftOption, rightOption);
}
for (const rightOption of Object.values(right.options).sort(compareOrder)) {
const leftOption = left.options[rightOption.name];
if (!leftOption) {
append(undefined, rightOption);
}
}
return result;
}

export interface ImmutableUSIEngines {
hasEngine(uri: string): boolean;
getEngine(uri: string): USIEngine | undefined;
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/view/dialog/PlayerSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<span class="player-info-value">{{ multiPVState || "---" }}</span>
</div>
<button
v-if="enableEditButton"
class="player-settings"
:disabled="!isPlayerSettingsEnabled"
@click="openPlayerSettings"
Expand Down Expand Up @@ -107,6 +108,10 @@ const props = defineProps({
type: Boolean,
default: false,
},
enableEditButton: {
type: Boolean,
default: true,
},
});
const emit = defineEmits<{
Expand Down
37 changes: 35 additions & 2 deletions src/renderer/view/dialog/USIEngineManagementDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
</div>
</div>
</div>
<button class="wide" @click="add()">{{ t.add }}</button>
<div class="menu row">
<button class="wide" @click="add()">{{ t.add }}</button>
<button class="wide" @click="openMerge()">{{ t.compareAndMerge }}</button>
</div>
<div class="main-buttons">
<button data-hotkey="Enter" autofocus @click="saveAndClose()">
{{ t.saveAndClose }}
Expand All @@ -74,13 +77,25 @@
@ok="optionOk"
@cancel="optionCancel"
/>
<USIEngineMergeDialog
v-if="mergeDialog"
:engines="usiEngines"
@ok="mergeOk"
@cancel="mergeCancel"
/>
</template>

<script setup lang="ts">
import { t } from "@/common/i18n";
import { filter as filterString } from "@/common/helpers/string";
import api from "@/renderer/ipc/api";
import { duplicateEngine, USIEngine, USIEngines, USIEngineLabel } from "@/common/settings/usi";
import {
duplicateEngine,
USIEngine,
USIEngines,
USIEngineLabel,
ImmutableUSIEngines,
} from "@/common/settings/usi";
import { useStore } from "@/renderer/store";
import { ref, onMounted, onBeforeUnmount, computed, onUpdated } from "vue";
import USIEngineOptionsDialog from "@/renderer/view/dialog/USIEngineOptionsDialog.vue";
Expand All @@ -90,11 +105,13 @@ import { installHotKeyForDialog, uninstallHotKeyForDialog } from "@/renderer/dev
import { useAppSettings } from "@/renderer/store/settings";
import { useErrorStore } from "@/renderer/store/error";
import { useBusyState } from "@/renderer/store/busy";
import USIEngineMergeDialog from "./USIEngineMergeDialog.vue";
const store = useStore();
const busyState = useBusyState();
const dialog = ref();
const optionDialog = ref(null as USIEngine | null);
const mergeDialog = ref(false);
const usiEngines = ref(new USIEngines());
const filter = ref();
const filterWords = ref([] as string[]);
Expand Down Expand Up @@ -184,6 +201,10 @@ const openOptions = (uri: string) => {
optionDialog.value = usiEngines.value.getEngine(uri) as USIEngine;
};
const openMerge = () => {
mergeDialog.value = true;
};
const duplicate = (uri: string) => {
const src = usiEngines.value.getEngine(uri) as USIEngine;
const engine = duplicateEngine(src);
Expand Down Expand Up @@ -215,6 +236,15 @@ const optionOk = (engine: USIEngine) => {
const optionCancel = () => {
optionDialog.value = null;
};
const mergeOk = (engines: ImmutableUSIEngines) => {
usiEngines.value = engines.getClone();
mergeDialog.value = false;
};
const mergeCancel = () => {
mergeDialog.value = false;
};
</script>

<style scoped>
Expand All @@ -230,6 +260,9 @@ const optionCancel = () => {
.filter {
width: 100%;
}
.menu > *:not(:first-child) {
margin-left: 5px;
}
.engine {
margin: 0px 5px 0px 5px;
padding: 5px;
Expand Down
Loading

0 comments on commit abace1a

Please sign in to comment.