Skip to content

Commit

Permalink
fix: 修复最大最小值设置错误导致无法进行游戏的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
libondev authored Apr 10, 2024
1 parent 05c7aa5 commit 87d74c5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/composables/use-game-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export function useGameStatus() {
// 如果最小数量大于最大数量,交换两者
if (levelConfig.min > levelConfig.max) {
// @ts-expect-error let me do this!
// eslint-disable-next-line style/max-statements-per-line
min = levelConfig.max; max = levelConfig.min
[levelConfig.min, levelConfig.max] = [levelConfig.max, levelConfig.min]
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"maximum-blocks": "Maximum number of generated blocks",
"hp": "HP",
"second": "second",
"setup-completed": "Setup completed, start the game",
"save-success": "Save success",
"setup-completed": "Start the game",

"score": "Score",
"start-time": "Start time",
Expand Down
3 changes: 2 additions & 1 deletion src/locale/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"maximum-blocks": "生成されるブロックの最大数",
"hp": "HP",
"second": "",
"setup-completed": "セットアップが完了しました。ゲームを開始します",
"save-success": "設定が正常に保存されました",
"setup-completed": "ゲームをスタート",

"score": "スコア",
"start-time": "開始時刻",
Expand Down
9 changes: 5 additions & 4 deletions src/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
"maximum-blocks": "最大生成方块数",
"hp": "生命值",
"second": "",
"setup-completed": "设置完成,开始游戏",

"save-success": "设置成功",
"setup-completed": "开始游戏",

"score": "得分",
"start-time": "开始于",
"end-time": "结束于",
"using-time": "用时",

"game-over": "游戏结束",
"start": "游戏开始",
"again": "再来一次",
"clear": "清空选中",
"selected": "选好了",
"continue": "继续",

"memory-time": "每回合开始前的记忆时间",
"configuration-integer-gt": "配置只能为大于 1 的整数",
"select-one-first": "请先选择至少一个方块",
Expand Down
41 changes: 26 additions & 15 deletions src/views/settings/custom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ const customLevelConfig = ref((() => {
return configValue
})())
let toastTimeout = 0
function saveCustomLevelConfig() {
if (toastTimeout) {
return
}
const illegalValue = Object.values<number>(customLevelConfig.value).find(v => typeof v !== 'number' || v <= 0 || !Number.isInteger(v))
if (illegalValue) {
Expand All @@ -38,21 +44,26 @@ function saveCustomLevelConfig() {
size = 'size-9'
}
// 保证 min 小于等于 max
if (min > max) {
[customLevelConfig.value.max, customLevelConfig.value.min] = [customLevelConfig.value.min, customLevelConfig.value.max]
}
// 如果最大/最小值超过了格子数,就设置为格子数
if (max > grid * grid) {
customLevelConfig.value.max = grid * grid
} else if (min > grid * grid) {
}
if (min > grid * grid) {
customLevelConfig.value.min = grid * grid
}
// 保证 min 小于等于 max
if (min > max) {
[customLevelConfig.value.max, customLevelConfig.value.min] = [customLevelConfig.value.min, customLevelConfig.value.max]
}
localStorage.setItem('customLevelConfig', JSON.stringify({ size, ...customLevelConfig.value }))
router.push('/game/custom')
toastTimeout = window.setTimeout(() => {
useToast($t('save-success', '设置成功'))
router.push('/game/custom')
}, 300)
}
</script>

Expand All @@ -64,18 +75,18 @@ function saveCustomLevelConfig() {
</h2>

<div class="mb-4">
<span class="text-sm">{{ $t('number-of-grids', '网格数量') }}<i class="text-gray-500">X * Y)</i></span>
<Input v-model.number="customLevelConfig.grid" type="number" maxlength="2" />
<span class="text-sm">{{ $t('number-of-grids', '网格数量') }}<span class="text-gray-500">&nbsp;(X * Y)</span></span>
<Input v-model.number="customLevelConfig.grid" type="number" min="1" max="99" />
</div>

<div class="mb-4">
<span class="text-sm">{{ $t('minimum-blocks', '最小生成方块数') }}</span>
<Input v-model.number="customLevelConfig.min" type="number" maxlength="2" />
<Input v-model.number="customLevelConfig.min" type="number" min="1" max="99" />
</div>

<div class="mb-4">
<span class="text-sm">{{ $t('maximum-blocks', '最大生成方块数') }}</span>
<Input v-model.number="customLevelConfig.max" type="number" maxlength="2" />
<span class="text-sm">{{ $t('maximum-blocks', '最大生成方块数') }}<span class="text-gray-500">&nbsp;(MAX = {{ customLevelConfig.grid * customLevelConfig.grid }})</span></span>
<Input v-model.number="customLevelConfig.max" type="number" min="1" max="99" />
</div>

<!-- <div class="mb-4">
Expand All @@ -89,12 +100,12 @@ function saveCustomLevelConfig() {
</div>

<div class="mb-8">
<span class="text-sm">{{ $t('memory-time', '每回合开始前的记忆时间') }}<i class="text-gray-500">{{ $t('second', '秒') }})</i></span>
<Input v-model.number="customLevelConfig.internal" type="number" maxlength="2" />
<span class="text-sm text-balance">{{ $t('memory-time', '每回合开始前的记忆时间') }}<span class="text-gray-500">({{ $t('second', '秒') }})</span></span>
<Input v-model.number="customLevelConfig.internal" type="number" min="1" max="99" />
</div>

<Button type="primary">
{{ $t('setup-completed', '设置完成,开始游戏') }}
{{ $t('setup-completed', '开始游戏') }}
</Button>
</form>
</div>
Expand Down

0 comments on commit 87d74c5

Please sign in to comment.