blob: b0c2fc62de3a800282e25992022635bea35e3528 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
namespace LivingVillage.Desktop
open System
module ChineseText =
type SceneKind =
| VillageScene
| Waterway
| WhiteWallHome
| StoneBridgeScene
| BambooGrove
| VegetableGardenScene
type DayNightKind =
| DayTime
| NightTime
type MenuHeadingKind =
| MainMenuHeading
| SettingsHeading
| ControlsHeading
type StatusHeadingKind =
| StatusHeading
| ReadyStatus
| PausedStatus
type ChineseCopy =
{ SceneTitle: string
Ready: string }
type TextLayout =
{ Lines: string list
MissingGlyphs: char list }
let sceneLabel scene =
match scene with
| VillageScene -> "江南水乡"
| Waterway -> "水道"
| WhiteWallHome -> "白墙黛瓦民居"
| StoneBridgeScene -> "石桥"
| BambooGrove -> "竹林"
| VegetableGardenScene -> "菜圃"
let dayNightLabel time =
match time with
| DayTime -> "白天"
| NightTime -> "夜晚"
let menuHeading heading =
match heading with
| MainMenuHeading -> "主菜单"
| SettingsHeading -> "设置"
| ControlsHeading -> "操作说明"
let statusHeading status =
match status with
| StatusHeading -> "状态"
| ReadyStatus -> "准备就绪"
| PausedStatus -> "已暂停"
let copy : ChineseCopy =
{ SceneTitle = "江南水乡"
Ready = "准备就绪" }
let layoutText (maxWidth: int) (supported: Set<char>) (text: string) : TextLayout =
let width = max 1 maxWidth
let normalized, missing =
text
|> Seq.fold
(fun (characters, missingGlyphs) character ->
if Set.contains character supported then
character :: characters, missingGlyphs
else
'□' :: characters, character :: missingGlyphs)
([], [])
{ Lines =
normalized
|> List.rev
|> List.chunkBySize width
|> List.map (fun line -> new String(Array.ofList line))
MissingGlyphs = List.rev missing }
|