LMCassette // Generate wildcard table even if wildcardKey is missing.
This commit is contained in:
parent
e47d5749e9
commit
c88c8bda64
|
@ -37,6 +37,8 @@ extension vChewingLM {
|
||||||
private static let fscale = 2.7
|
private static let fscale = 2.7
|
||||||
private var norm = 0.0
|
private var norm = 0.0
|
||||||
|
|
||||||
|
/// 萬用花牌字符,哪怕花牌鍵仍不可用。
|
||||||
|
public var wildcard: String { wildcardKey.isEmpty ? "†" : wildcardKey }
|
||||||
/// 資料陣列內承載的資料筆數。
|
/// 資料陣列內承載的資料筆數。
|
||||||
public var count: Int { charDefMap.count }
|
public var count: Int { charDefMap.count }
|
||||||
/// 是否已有資料載入。
|
/// 是否已有資料載入。
|
||||||
|
@ -103,11 +105,9 @@ extension vChewingLM {
|
||||||
charDefMap[strFirstCell, default: []].append(strSecondCell)
|
charDefMap[strFirstCell, default: []].append(strSecondCell)
|
||||||
reverseLookupMap[strSecondCell, default: []].append(strFirstCell)
|
reverseLookupMap[strSecondCell, default: []].append(strFirstCell)
|
||||||
var keyComps = strFirstCell.charComponents
|
var keyComps = strFirstCell.charComponents
|
||||||
while !keyComps.isEmpty, !wildcardKey.isEmpty {
|
while !keyComps.isEmpty {
|
||||||
keyComps.removeLast()
|
keyComps.removeLast()
|
||||||
if !wildcardKey.isEmpty {
|
charDefWildcardMap[keyComps.joined() + wildcard, default: []].append(strSecondCell)
|
||||||
charDefWildcardMap[keyComps.joined() + wildcardKey, default: []].append(strSecondCell)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if loadingOctagramData, !strLine.contains("%octagram") {
|
} else if loadingOctagramData, !strLine.contains("%octagram") {
|
||||||
guard let countValue = Int(cells[1]) else { continue }
|
guard let countValue = Int(cells[1]) else { continue }
|
||||||
|
@ -180,7 +180,7 @@ extension vChewingLM {
|
||||||
let arrRaw = charDefMap[key]?.deduplicated ?? []
|
let arrRaw = charDefMap[key]?.deduplicated ?? []
|
||||||
var arrRawWildcard: [String] = []
|
var arrRawWildcard: [String] = []
|
||||||
if let arrRawWildcardValues = charDefWildcardMap[key]?.deduplicated,
|
if let arrRawWildcardValues = charDefWildcardMap[key]?.deduplicated,
|
||||||
key.contains(wildcardKey), key.first?.description != wildcardKey
|
key.contains(wildcard), key.first?.description != wildcard
|
||||||
{
|
{
|
||||||
arrRawWildcard.append(contentsOf: arrRawWildcardValues)
|
arrRawWildcard.append(contentsOf: arrRawWildcardValues)
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ extension vChewingLM {
|
||||||
/// - key: 讀音索引鍵。
|
/// - key: 讀音索引鍵。
|
||||||
public func hasUnigramsFor(key: String) -> Bool {
|
public func hasUnigramsFor(key: String) -> Bool {
|
||||||
charDefMap[key] != nil
|
charDefMap[key] != nil
|
||||||
|| (charDefWildcardMap[key] != nil && key.contains(wildcardKey) && key.first?.description != wildcardKey)
|
|| (charDefWildcardMap[key] != nil && key.contains(wildcard) && key.first?.description != wildcard)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Private Functions.
|
// MARK: - Private Functions.
|
||||||
|
|
|
@ -174,6 +174,7 @@ extension InputHandler {
|
||||||
private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? {
|
private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? {
|
||||||
guard let delegate = delegate else { return nil }
|
guard let delegate = delegate else { return nil }
|
||||||
var wildcardKey: String { currentLM.currentCassette.wildcardKey } // 花牌鍵。
|
var wildcardKey: String { currentLM.currentCassette.wildcardKey } // 花牌鍵。
|
||||||
|
var wildcard: String { currentLM.currentCassette.wildcard } // 花牌鍵。
|
||||||
let isWildcardKeyInput: Bool = (input.text == wildcardKey && !wildcardKey.isEmpty)
|
let isWildcardKeyInput: Bool = (input.text == wildcardKey && !wildcardKey.isEmpty)
|
||||||
|
|
||||||
var keyConsumedByStrokes = false
|
var keyConsumedByStrokes = false
|
||||||
|
@ -182,8 +183,8 @@ extension InputHandler {
|
||||||
|| input.isControlHold || input.isOptionHold || input.isShiftHold || input.isCommandHold
|
|| input.isControlHold || input.isOptionHold || input.isShiftHold || input.isCommandHold
|
||||||
|
|
||||||
var isLongestPossibleKeyFormed: Bool {
|
var isLongestPossibleKeyFormed: Bool {
|
||||||
guard !isWildcardKeyInput, !wildcardKey.isEmpty else { return false }
|
guard !isWildcardKeyInput else { return false }
|
||||||
return !currentLM.currentCassette.hasUnigramsFor(key: calligrapher + wildcardKey) && !calligrapher.isEmpty
|
return !currentLM.currentCassette.hasUnigramsFor(key: calligrapher + wildcard) && !calligrapher.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
var isStrokesFull: Bool {
|
var isStrokesFull: Bool {
|
||||||
|
@ -199,7 +200,7 @@ extension InputHandler {
|
||||||
delegate.switchState(newEmptyState)
|
delegate.switchState(newEmptyState)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if isStrokesFull {
|
while isStrokesFull {
|
||||||
calligrapher = String(calligrapher.dropLast(1))
|
calligrapher = String(calligrapher.dropLast(1))
|
||||||
}
|
}
|
||||||
calligrapher.append(input.text)
|
calligrapher.append(input.text)
|
||||||
|
|
Loading…
Reference in New Issue