Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加蓝天双拼与大牛双拼方案 #31

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/Hanzi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { effect, ref } from "vue";
import { useStore } from "../store";
import { getPinyinOf } from "../utils/hanzi";
import { randomChoice } from "../utils/number";

const props = defineProps<{
hanziSeq: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/components/Keyboard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, watchPostEffect } from "vue";
import { computed } from "vue";
import { storeToRefs } from "pinia";
import { ref, onActivated, onDeactivated } from "vue";
import { useStore } from "../store";
Expand Down
2 changes: 1 addition & 1 deletion src/components/MenuList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { ref, defineProps, computed, onMounted, onUnmounted } from "vue";
import { defineProps, onMounted, onUnmounted } from "vue";

export interface MenuProps {
onMenuChange?: (i: number) => void;
Expand Down
3 changes: 1 addition & 2 deletions src/components/Pinyin.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts" setup>
import { computed } from "vue";
import { defineProps } from "vue";

const props = defineProps<{
defineProps<{
chars: string[];
}>();
</script>
Expand Down
10 changes: 5 additions & 5 deletions src/components/SingleMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { computed } from "vue";
import { getPinyinOf } from "../utils/hanzi";
import { TypingSummary } from "../utils/summary";
import { followKeys, leadKeys } from "../utils/pinyin";
import { randInt, randomChoice } from "../utils/number";
import { randInt } from "../utils/number";

export interface SingleModeProps {
nextChar?: () => string;
Expand All @@ -21,7 +21,7 @@ export interface SingleModeProps {
mode?: "Lead" | "Follow";
}

function nextChar() {
function getNextChar() {
if (!props.mode) {
return props.nextChar?.() ?? "";
}
Expand All @@ -32,7 +32,7 @@ const pinyin = ref<string[]>([]);

const store = useStore();
const props = defineProps<SingleModeProps>();
const hanziSeq = ref(new Array(4).fill(0).map(() => nextChar()));
const hanziSeq = ref(new Array(4).fill(0).map(() => getNextChar()));
const isValid = ref(false);

const summary = ref(new TypingSummary());
Expand Down Expand Up @@ -78,7 +78,7 @@ function onMenuChange(i: number) {

watchPostEffect(() => {
for (let i = 0; i < 4; ++i) {
hanziSeq.value.unshift(nextChar());
hanziSeq.value.unshift(getNextChar());
hanziSeq.value.pop();
}
});
Expand Down Expand Up @@ -132,7 +132,7 @@ function onSeq([lead, follow]: [string?, string?]) {
watchPostEffect(() => {
if (isValid.value) {
setTimeout(() => {
hanziSeq.value.unshift(nextChar());
hanziSeq.value.unshift(getNextChar());
hanziSeq.value.pop();
pinyin.value = [];
isValid.value = false;
Expand Down
8 changes: 4 additions & 4 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ declare type Char =
type Pinyin = { lead: string; follow: string; full: string };

interface Progress {
currentIndex: number = 0;
total: number = 0;
correctTry: number = 0;
totalTry: number = 0;
currentIndex: number;
total: number;
correctTry: number;
totalTry: number;
}

interface Combine {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/FollowMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import SingleMode from '../components/SingleMode.vue';
import { followMap, followKeys } from '../utils/pinyin'
import { useStore } from '../store'
import { computed, ref } from 'vue';
import { computed } from 'vue';
import { hanziMap } from '../utils/hanzi';
import { storeToRefs } from 'pinia';

Expand Down
1 change: 0 additions & 1 deletion src/pages/PragraphMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
watchPostEffect,
onActivated,
onDeactivated,
onMounted,
watchEffect,
} from "vue";
import { useStore } from "../store";
Expand Down
41 changes: 39 additions & 2 deletions src/utils/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ declare global {
* ],
* zeroMap: [ // 零声母映射
* '${双拼按键}/${对应拼音}'
* ],
* additionalMap: [ // 附加映射
* '${双拼按键}/${对应拼音}'
* ],
* excludingMap: [ // 不匹配映射
* '${双拼按键}/${对应拼音}'
* ]
* }
* ```
*/
type RawShuangPinConfig = typeof configs["小鹤双拼"];
type RawShuangPinConfig = {
keyMap: string[],
zeroMap: string[],
additionalMap?: string[],
excludingMap?: string[],
};
type ShuangpinMode = ShuangpinConfig;
}

Expand All @@ -33,6 +44,7 @@ export class ShuangpinConfig {
zero2sp = new Map<string, string>(); // 双拼 -> 零声母
sp2py = new Map<string, string>(); // 双拼 -> 拼音
py2sp = new Map<string, string>(); // 拼音 -> 双拼
spNot2py = new Map<string, string>(); // 不匹配映射:双拼 -> 拼音

constructor(
public name: string,
Expand All @@ -41,6 +53,9 @@ export class ShuangpinConfig {
) {
for (const line of config["keyMap"]) {
const [main, follow, lead] = line.split("/");
if (!follow && !lead) {
continue;
}
const keyConfig: KeyConfig = {
main: (main as Char) ?? "",
follows: follow?.split(",") ?? [],
Expand All @@ -60,6 +75,22 @@ export class ShuangpinConfig {
this.py2sp.set(zero, sp);
this.sp2py.set(sp, zero);
}
const additionalMap = config["additionalMap"];
if (additionalMap) {
for (const line of additionalMap) {
const [sp, pinyin] = line.split("/");
this.py2sp.set(pinyin, sp);
this.sp2py.set(sp, pinyin);
}
}

const excludingMap = config["excludingMap"];
if (excludingMap) {
for (const line of excludingMap) {
const [sp, pinyin] = line.split("/");
this.spNot2py.set(sp, pinyin);
}
}

const allCombs = product(
[...this.groupByKey.keys()],
Expand All @@ -72,8 +103,14 @@ export class ShuangpinConfig {
const pinyins = product(leads, follows);
for (const [l, f] of pinyins) {
const pinyin = l + f;
if (!(l && f)) {
continue;
}
if (pinyin == this.spNot2py.get(sp)) {
continue;
}
if (validCombines.has(pinyin)) {
this.py2sp.set(pinyin, sp);
this.py2sp.set(pinyin, sp.concat(this.py2sp.get(pinyin) ?? ""));
this.sp2py.set(sp, pinyin);
}
}
Expand Down
108 changes: 108 additions & 0 deletions src/utils/spconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -400,5 +400,113 @@
"oo/o",
"op/ou"
]
},
"蓝天双拼": {
"keyMap": [
"q/ua/q",
"w/ei/w",
"e/e/",
"r/ou/r",
"t/iu/t",
"y/ue,ve/y",
"u/u/sh",
"i/i/ch",
"o/uo,o/",
"p/ie/p",
"a/a/",
"s/iong,ong/s",
"d/ai/d",
"f/ing,uai/f",
"g/ang/g",
"h/uan/h",
"j/an/j",
"k/en,ia/k",
"l/iang,uang/l",
";//",
"z/eng/z",
"x/in/x",
"c/ao/c",
"v/ui,v/zh",
"b/un/b",
"n/iao/n",
"m/ian/m"
],
"zeroMap": [
"aa/a",
"ai/ai",
"an/an",
"ag/ang",
"ao/ao",
"ee/e",
"ei/ei",
"en/en",
"ez/eng",
"er/er",
"oo/o",
"ou/ou"
]
},
"大牛双拼": {
"keyMap": [
"q/ua,ian/q",
"w/vn,ei/w",
"e/e/",
"r/ou/r",
"t/iu/t",
"y/un/y",
"u/u,er/sh",
"i/i/ch",
"o/o,uo/zh",
"p/ie/p",
"a/a/zh",
"s/ao/s",
"d/an/d",
"f/ang/f",
"g/uai,ing/g",
"h/ai,ue/h",
"j/eng,van/j",
"k/en,ia/k",
"l/ong,iong/l",
";//",
"z/uan/z",
"x/ve,uang/x",
"c/ian/c",
"v/ui,v/sh",
"b/in/b",
"n/ui,iang/n",
"m/iao/m"
],
"zeroMap": [
"ea/a",
"eh/ai",
"ed/an",
"ef/ang",
"es/ao",
"ee/e",
"ew/ei",
"ek/en",
"ej/eng",
"eu/er",
"eo/o",
"er/ou"
],
"additionalMap": [
"jw/jun",
"qw/qun",
"xw/xun",
"yw/yun",
"jj/juan",
"qj/quan",
"xj/xuan",
"yj/yuan",
"jx/jue",
"qx/que",
"xx/xue",
"yx/yue",
"jv/ju",
"qv/qu",
"xv/xu",
"yv/yu"
]
}
}