@aivin-labs/cli 1.0.8 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/bin/assets/aivin-mascot.png +0 -0
- package/bin/cli.mjs +1979 -1780
- package/bin/lib/browserAutomation.mjs +232 -469
- package/bin/lib/localBrowser.mjs +345 -0
- package/bin/lib/remote/activityLog.mjs +1 -1
- package/bin/lib/remote/autoStart.mjs +174 -14
- package/bin/lib/remote/browserTunnel.mjs +187 -37
- package/bin/lib/remote/callLedger.mjs +74 -15
- package/bin/lib/remote/cdpPolicy.mjs +14 -1
- package/bin/lib/remote/client.mjs +174 -11
- package/bin/lib/remote/clipboard.mjs +138 -0
- package/bin/lib/remote/cloudFiles.mjs +53 -0
- package/bin/lib/remote/codingAgents.mjs +293 -0
- package/bin/lib/remote/constants.mjs +78 -0
- package/bin/lib/remote/dailyBrowser.mjs +9 -3
- package/bin/lib/remote/desktop/desktopCast.mjs +198 -0
- package/bin/lib/remote/desktop/desktopCastSource.mjs +514 -0
- package/bin/lib/remote/desktop/desktopWebRtc.mjs +95 -0
- package/bin/lib/remote/desktop/index.mjs +309 -0
- package/bin/lib/remote/desktop/linux.mjs +144 -0
- package/bin/lib/remote/desktop/linuxTraySource.mjs +434 -0
- package/bin/lib/remote/desktop/mac.mjs +187 -0
- package/bin/lib/remote/desktop/macTraySource.mjs +295 -0
- package/bin/lib/remote/desktop/strings.mjs +74 -0
- package/bin/lib/remote/desktop/traySource.mjs +541 -0
- package/bin/lib/remote/deviceProfile.mjs +1 -0
- package/bin/lib/remote/docText.mjs +86 -1
- package/bin/lib/remote/fileIndexer.mjs +757 -399
- package/bin/lib/remote/folderRules.mjs +140 -0
- package/bin/lib/remote/gui/index.mjs +208 -18
- package/bin/lib/remote/gui/windowsHost.mjs +9 -2
- package/bin/lib/remote/gui/windowsHostSource.mjs +444 -49
- package/bin/lib/remote/idempotency.mjs +50 -21
- package/bin/lib/remote/localPolicy.mjs +17 -4
- package/bin/lib/remote/mascot/adpcm.mjs +70 -0
- package/bin/lib/remote/mascot/ask.mjs +768 -0
- package/bin/lib/remote/mascot/askHostSource.mjs +530 -0
- package/bin/lib/remote/mascot/assets.mjs +825 -216
- package/bin/lib/remote/mascot/bot.mjs +397 -0
- package/bin/lib/remote/mascot/hostSource.mjs +500 -103
- package/bin/lib/remote/mascot/hotkey.mjs +66 -0
- package/bin/lib/remote/mascot/index.mjs +199 -28
- package/bin/lib/remote/mascot/labels.mjs +2 -3
- package/bin/lib/remote/mascot/rigSource.mjs +614 -0
- package/bin/lib/remote/mascot/strings.mjs +204 -18
- package/bin/lib/remote/mascot/ui.mjs +104 -0
- package/bin/lib/remote/mascot/voiceSource.mjs +584 -0
- package/bin/lib/remote/meeting/index.mjs +415 -0
- package/bin/lib/remote/meeting/recorder.mjs +109 -0
- package/bin/lib/remote/meeting/recorderSource.mjs +394 -0
- package/bin/lib/remote/meeting/transcribe.mjs +259 -0
- package/bin/lib/remote/osSearch.mjs +107 -0
- package/bin/lib/remote/sqliteDb.mjs +51 -0
- package/bin/lib/remote/tabGroups.mjs +209 -0
- package/bin/lib/remote/toolHandlers.mjs +788 -726
- package/bin/lib/remoteControl.mjs +26 -26
- package/docs/AIVIN_MASCOT.md +130 -0
- package/docs/CLI.md +1504 -1353
- package/docs/media/aivin-mascot-live.gif +0 -0
- package/docs/media/aivin-mascot-live.png +0 -0
- package/docs/media/aivin-remote-architecture.svg +102 -0
- package/package.json +71 -71
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import { BOT_BLINKS, BOT_EYES, BOT_MOTION, BOT_MOUTHS, BOT_RIG, BOT_SPINS, SCREEN_SCROLL_LOOP } from './bot.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bộ chuyển động của linh vật (29/10/2026) — mã C# biên dịch trong host.ps1 (Add-Type, cùng khối với AivinMascot.Native), chạy theo
|
|
5
|
+
* CompositionTarget.Rendering (đúng nhịp màn hình). Trước đây vòng lặp viết bằng PowerShell: mỗi khung hình chạy script thông dịch +
|
|
6
|
+
* FindName hàng chục lần; C# giữ sẵn tham chiếu, rẻ hơn nhiều và cho phép mô phỏng lò xo theo bước nhỏ.
|
|
7
|
+
*
|
|
8
|
+
* - Thông số theo trạng thái: BOT_MOTION (bot.mjs) — sinh thành bảng `Motion.For` dưới đây. Giá trị hiện tại trượt dần về đích, pha nhún
|
|
9
|
+
* cộng dồn → đổi trạng thái / đổi nhịp không giật.
|
|
10
|
+
* - Quán tính: đầu xoay quanh cổ bằng lò xo (hơi vượt rồi về), đầu trễ nhịp so với thân khi nhún; ăng-ten là lò xo ít hãm, bị kéo theo gia
|
|
11
|
+
* tốc xoay của đầu, cú nhảy, cú kéo cửa sổ → lắc lư tự nhiên.
|
|
12
|
+
* - Mắt: chớp ngẫu nhiên (thỉnh thoảng chớp đôi), tự liếc khi rảnh, theo con trỏ khi con trỏ ở gần hoặc vừa di chuyển (ở đâu trên màn hình
|
|
13
|
+
* cũng lia theo, đúng hướng — kể cả khi agent điều khiển chuột), con trỏ đứng yên xa thì thôi; đang làm thì mắt ở trên các màn (trừ khi
|
|
14
|
+
* rê chuột lên bot);
|
|
15
|
+
* mặt dịch nhẹ cùng hướng nhìn cho cảm giác khối.
|
|
16
|
+
* - Đang làm: ba màn hình 3D lật bung ra quanh bot (so le), trôi nhẹ, chữ cuộn / cột nhảy; bot chăm chú nhìn lần lượt từng màn — mắt +
|
|
17
|
+
* đầu hướng theo màn, màn đang nhìn sáng lên, ở màn chính mắt quét từng dòng như đang đọc. Offline: chữ "z" bay lên.
|
|
18
|
+
* - Đổi nét mặt (SetFace): mắt khép dẹt lại, đổi kiểu mắt lúc đang khép rồi mở ra nảy nhẹ; miệng theo sau một nhịp (thu lại, đổi, bật ra) —
|
|
19
|
+
* mọi kiểu mắt / miệng đều chuyển được, kể cả mắt cong không chớp được. Màu đèn ăng-ten chuyển dần sang màu trạng thái mới.
|
|
20
|
+
* - Phản ứng (Play, cửa sổ chọn theo cặp trạng thái): startle (đang làm → cần bạn: giật mình, mắt bật to), relief (xong sau khi lỗi: chùng
|
|
21
|
+
* xuống thở ra rồi nhổm lên), cheer (xong việc dài: nhảy hai lần, lấp lánh hai đợt), small (xong việc ngắn: gật thay vì nhảy), ack (đã
|
|
22
|
+
* nhận câu hỏi: gật nhẹ), yawn (ngáp trước khi ngủ gật). Attend: đang gõ trong ô hỏi → nhìn về ô hỏi.
|
|
23
|
+
* - Sống trong trạng thái dài: thưa thớt (ngẫu nhiên 22–42 s, không khi đang rê chuột / kéo / ngay sau một phản ứng) — đang làm lâu thì nheo
|
|
24
|
+
* mắt tập trung hoặc gật gù; chờ lâu thì nghiêng đầu nhìn về con trỏ như hỏi, mỗi lần đậm hơn một chút (có trần).
|
|
25
|
+
* - Đạo cụ theo trạng thái: "!" nảy khi chờ xác nhận, bong bóng ba chấm khi nghĩ, tia lấp lánh bung ra khi xong việc.
|
|
26
|
+
* - Thùng nhận tệp (Tray, cửa sổ gọi): kéo tệp tới gần → thùng bật ra trước bụng, nắp mở, mũi tên nhún; không nhận được → nắp đóng, ✕ đỏ,
|
|
27
|
+
* lắc; thả → "nuốt" (Play gulp); tệp chờ gửi → ôm thùng nhỏ có số tệp; gửi đi → thùng nhấc lên rồi biến mất.
|
|
28
|
+
* - Ngủ gật (Doze, cửa sổ gọi khi rảnh lâu): mắt nhắm, đầu gục, zzz, thỉnh thoảng giật mình ngẩng lên; thức dậy thì nhổm lên + lắc ăng-ten.
|
|
29
|
+
* - Cử chỉ khi vào trạng thái (`enter`): hop (nhảy + nén / giãn), shake (lắc đầu tắt dần), nod (gật), perk (nhổm lên chú ý, lặp khi chờ).
|
|
30
|
+
* - Cửa sổ ẩn → bỏ qua khung hình (không tốn CPU / GPU).
|
|
31
|
+
* Giữ ASCII (PowerShell 5 đọc .ps1 không BOM theo bảng mã cũ).
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const n = (v) => (Number.isInteger(v) ? `${v}.0` : `${v}`);
|
|
35
|
+
const FIELDS = ['bob', 'bobHz', 'breathe', 'lean', 'headTilt', 'headY', 'antenna', 'glow', 'glowPulse', 'glowHz', 'tint', 'tintPulse', 'tintHz', 'scan', 'scale', 'opacity'];
|
|
36
|
+
const motionCase = ([name, m]) => ` case "${name}": return new Motion(new double[] { ${FIELDS.map((f) => n(m[f] ?? 0)).join(', ')} }, ${m.alt ? 'true' : 'false'}, ${m.look ? `true, ${n(m.look[0])}, ${n(m.look[1])}` : 'false, 0, 0'}, "${m.enter || ''}");`;
|
|
37
|
+
|
|
38
|
+
const V = BOT_RIG.visor;
|
|
39
|
+
const Z = BOT_RIG.zzz;
|
|
40
|
+
const SCREENS = BOT_RIG.screens;
|
|
41
|
+
const SP = BOT_RIG.sparks;
|
|
42
|
+
const TR = BOT_RIG.tray;
|
|
43
|
+
|
|
44
|
+
export const RIG_CS = String.raw`
|
|
45
|
+
public sealed class Motion {
|
|
46
|
+
public readonly double Bob, BobHz, Breathe, Lean, HeadTilt, HeadY, Antenna, Glow, GlowPulse, GlowHz, Tint, TintPulse, TintHz, Scan, Scale, Opacity, LookX, LookY;
|
|
47
|
+
public readonly bool Alt, HasLook; public readonly string Enter;
|
|
48
|
+
public Motion(double[] v, bool alt, bool hasLook, double lookX, double lookY, string enter) {
|
|
49
|
+
Bob = v[0]; BobHz = v[1]; Breathe = v[2]; Lean = v[3]; HeadTilt = v[4]; HeadY = v[5]; Antenna = v[6]; Glow = v[7]; GlowPulse = v[8]; GlowHz = v[9];
|
|
50
|
+
Tint = v[10]; TintPulse = v[11]; TintHz = v[12]; Scan = v[13]; Scale = v[14]; Opacity = v[15];
|
|
51
|
+
Alt = alt; HasLook = hasLook; LookX = lookX; LookY = lookY; Enter = enter;
|
|
52
|
+
}
|
|
53
|
+
public static Motion For(string s) {
|
|
54
|
+
switch (s) {
|
|
55
|
+
${Object.entries(BOT_MOTION).map(motionCase).join('\n')}
|
|
56
|
+
default: return For("idle");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One floating 3D screen (bot.mjs screens): its transforms, rest pose, where the bot looks to read it, how long it stays on it. */
|
|
62
|
+
public sealed class Screen {
|
|
63
|
+
public System.Windows.UIElement El; public System.Windows.Media.Media3D.AxisAngleRotation3D Tilt, Turn; public System.Windows.Media.Media3D.TranslateTransform3D Float; public TranslateTransform Scroll;
|
|
64
|
+
public readonly List<ScaleTransform> Bars = new List<ScaleTransform>();
|
|
65
|
+
public double RestTilt, RestTurn, LookX, LookY, Head, DwellMin, DwellMax, Lit;
|
|
66
|
+
public readonly Spring Pop = new Spring(0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Damped spring, integrated in small sub-steps so stiff springs stay stable on a slow frame. */
|
|
70
|
+
public sealed class Spring {
|
|
71
|
+
public double X, V;
|
|
72
|
+
public Spring(double x) { X = x; }
|
|
73
|
+
public double Step(double target, double k, double c, double dt) {
|
|
74
|
+
int n = (int)Math.Ceiling(dt / 0.008); double h = dt / n;
|
|
75
|
+
for (int i = 0; i < n; i++) { V += (k * (target - X) - c * V) * h; X += V * h; }
|
|
76
|
+
return X;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public sealed class Rig {
|
|
81
|
+
[DllImport("user32.dll")] static extern bool GetCursorPos(out POINT p);
|
|
82
|
+
[StructLayout(LayoutKind.Sequential)] struct POINT { public int X, Y; }
|
|
83
|
+
|
|
84
|
+
const double TAU = Math.PI * 2;
|
|
85
|
+
const double VISOR_SCAN = ${n(V.h + 14)};
|
|
86
|
+
const double SCREEN_LOOP = ${n(SCREEN_SCROLL_LOOP)};
|
|
87
|
+
// Body lean pivots on the feet: past ~50 deg a bottom corner of the body (61 units off the pivot) drops below the window edge and
|
|
88
|
+
// is clipped. Drags pile velocity onto the lean spring, so shaking hard used to swing it far beyond that.
|
|
89
|
+
const double LEAN_MAX = 16;
|
|
90
|
+
readonly System.Windows.FrameworkElement w;
|
|
91
|
+
readonly System.Windows.UIElement bot, shadow, earL, earR, visorFx, face;
|
|
92
|
+
readonly System.Windows.Shapes.Shape tint, halo;
|
|
93
|
+
readonly System.Windows.UIElement blushL, blushR;
|
|
94
|
+
readonly ScaleTransform botScale, shadowScale, faceScale, mouthOpen, talk;
|
|
95
|
+
readonly RotateTransform botLean, headRot, antRot;
|
|
96
|
+
readonly TranslateTransform botMove, headMove, faceLook, eyeLook, scanY;
|
|
97
|
+
readonly System.Windows.UIElement zzz, screensView, alert, think, sparks;
|
|
98
|
+
readonly ScaleTransform alertScale, thinkScale;
|
|
99
|
+
readonly RotateTransform alertRot;
|
|
100
|
+
readonly TranslateTransform alertMove;
|
|
101
|
+
readonly ScaleTransform propsScale;
|
|
102
|
+
readonly RotateTransform propsLean, propsHeadRot;
|
|
103
|
+
readonly TranslateTransform propsMove, propsHeadMove;
|
|
104
|
+
readonly List<TranslateTransform> thinkDots = new List<TranslateTransform>();
|
|
105
|
+
readonly List<System.Windows.UIElement> thinkDotEls = new List<System.Windows.UIElement>();
|
|
106
|
+
readonly List<System.Windows.UIElement> sparkEls = new List<System.Windows.UIElement>();
|
|
107
|
+
readonly List<TransformGroup> sparkXf = new List<TransformGroup>();
|
|
108
|
+
static readonly double[] SPARK_ANGLES = { ${SP.angles.map(n).join(', ')} };
|
|
109
|
+
double sparkAt = -10, nextJerk; bool dozing;
|
|
110
|
+
readonly List<Screen> screens = new List<Screen>();
|
|
111
|
+
int focus; double nextFocus, workAt = -10, headFocus;
|
|
112
|
+
readonly List<System.Windows.Controls.TextBlock> zs = new List<System.Windows.Controls.TextBlock>();
|
|
113
|
+
readonly List<ScaleTransform> blinks = new List<ScaleTransform>();
|
|
114
|
+
readonly double faceBase;
|
|
115
|
+
readonly Stopwatch clock = Stopwatch.StartNew();
|
|
116
|
+
readonly Random rnd = new Random();
|
|
117
|
+
TimeSpan lastRender = TimeSpan.MinValue; double last, now;
|
|
118
|
+
Motion m = Motion.For("idle"); string state = "idle";
|
|
119
|
+
|
|
120
|
+
public bool Hover, Pressed, Dragging;
|
|
121
|
+
// Smoothed state values (ease toward the state's targets).
|
|
122
|
+
double amp = 1.5, breathe, headTilt, headY, glow, glowPulse, tintV = .62, tintPulse, scan, scale = 1, opacity = 1, antRest, sleep;
|
|
123
|
+
double phase, glowPhase, tintPhase, scanPhase;
|
|
124
|
+
readonly Spring headA = new Spring(0), antA = new Spring(0), lean = new Spring(0), pop = new Spring(1), alertPop = new Spring(0), thinkPop = new Spring(0), press = new Spring(0), hover = new Spring(0);
|
|
125
|
+
readonly Spring lookX = new Spring(0), lookY = new Spring(0), near = new Spring(0);
|
|
126
|
+
int curX = int.MinValue, curY = int.MinValue; double curMovedAt = -10;
|
|
127
|
+
double prevHead, prevHeadVel, headAcc;
|
|
128
|
+
double nextBlink = 1.2, blinkAt = -10, blushAt = -10; bool doubleBlink;
|
|
129
|
+
double nextGlance = 2, glanceX, glanceY;
|
|
130
|
+
double hopAt = -10, shakeAt = -10, nodAt = -10, perkAt = -10, flashAt = -10;
|
|
131
|
+
bool hopKick, landKick;
|
|
132
|
+
// Play (Play()): dizzy = head circles + spiral eyes spin; giggle = quick little bounces; purr = leaning in, slow antenna wag (kept alive
|
|
133
|
+
// while petting goes on).
|
|
134
|
+
double dizzyAt = -10, giggleAt = -10, purrUntil = -10, purrK;
|
|
135
|
+
readonly List<RotateTransform> spins = new List<RotateTransform>();
|
|
136
|
+
const double DIZZY_S = 2.6, GIGGLE_S = 1.1;
|
|
137
|
+
// Reactions (Play) + life in a long state: when each started; the next spontaneous gesture; how insistent the waiting "ask" has got.
|
|
138
|
+
double stateAt, sighAt = -10, hop2At = -10, yawnAt = -10, squintAt = -10, askAt = -10, reactAt = -10, nextLife;
|
|
139
|
+
int askLevel; double askSide = 1;
|
|
140
|
+
// Attend (typing in the ask box): look at the box until this time; where the box is (eye offset units, like the cursor look).
|
|
141
|
+
double attendUntil = -10, attendX, attendY;
|
|
142
|
+
// Face morph (SetFace): the shown eye / mouth kind, the one waiting to swap in, squash springs (1 = full size), when the mouth starts.
|
|
143
|
+
readonly Dictionary<string, System.Windows.UIElement[]> eyeEls = new Dictionary<string, System.Windows.UIElement[]>();
|
|
144
|
+
readonly Dictionary<string, System.Windows.UIElement> mouthEls = new Dictionary<string, System.Windows.UIElement>();
|
|
145
|
+
readonly ScaleTransform eyeMorphL, eyeMorphR, mouthMorph;
|
|
146
|
+
string eyesNow, eyesNext, mouthNow, mouthNext; double mouthAt;
|
|
147
|
+
readonly Spring eyeSq = new Spring(1), mouthSq = new Spring(1);
|
|
148
|
+
const double MOUTH_LAG = 0.05;
|
|
149
|
+
// Antenna light color: eases from the old state's color to the new one.
|
|
150
|
+
readonly SolidColorBrush tintBrush = new SolidColorBrush();
|
|
151
|
+
Color colorFrom, colorTo; double colorAt = -10; bool hasColor;
|
|
152
|
+
const double COLOR_S = 0.45;
|
|
153
|
+
// Tray (Tray()): files dragged near the bot / dropped and waiting. Mode, files waiting, when the mode / a drop / a hand-over began.
|
|
154
|
+
readonly System.Windows.UIElement tray, trayArrow, trayBase, trayNo, trayDeny, trayBadge;
|
|
155
|
+
readonly ScaleTransform trayScale, trayBodyScale, trayBadgeScale;
|
|
156
|
+
readonly RotateTransform trayFlapL, trayFlapR, trayBodyLean;
|
|
157
|
+
readonly TranslateTransform trayMove, trayArrowMove, trayBodyMove;
|
|
158
|
+
readonly System.Windows.Controls.TextBlock trayCount;
|
|
159
|
+
readonly Spring trayPop = new Spring(0), trayLid = new Spring(0), badgePop = new Spring(0);
|
|
160
|
+
string trayMode = "off"; int trayN; double trayAt = -10, gulpAt = -10, giveAt = -10, denyK;
|
|
161
|
+
const double LID_OPEN = ${n(TR.lidOpen)};
|
|
162
|
+
|
|
163
|
+
T Get<T>(string name) where T : class {
|
|
164
|
+
var o = w.FindName(name) as T;
|
|
165
|
+
if (o == null) throw new InvalidOperationException("mascot rig: missing element " + name);
|
|
166
|
+
return o;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** root = the window (or any element whose name scope holds the bot, for offscreen previews driven by Tick). */
|
|
170
|
+
public Rig(System.Windows.FrameworkElement root) {
|
|
171
|
+
w = root;
|
|
172
|
+
bot = Get<System.Windows.UIElement>("Bot"); shadow = Get<System.Windows.UIElement>("Shadow");
|
|
173
|
+
earL = Get<System.Windows.UIElement>("EarGlowL"); earR = Get<System.Windows.UIElement>("EarGlowR");
|
|
174
|
+
visorFx = Get<System.Windows.UIElement>("VisorFx"); face = Get<System.Windows.UIElement>("Face");
|
|
175
|
+
tint = Get<System.Windows.Shapes.Shape>("AntennaTint"); halo = Get<System.Windows.Shapes.Shape>("AntennaHalo"); blushL = w.FindName("BlushL") as System.Windows.UIElement; blushR = w.FindName("BlushR") as System.Windows.UIElement;
|
|
176
|
+
botScale = Get<ScaleTransform>("BotScale"); shadowScale = Get<ScaleTransform>("ShadowScale"); faceScale = Get<ScaleTransform>("FaceScale");
|
|
177
|
+
mouthOpen = Get<ScaleTransform>("MouthOpenScale"); talk = Get<ScaleTransform>("MouthTalkScale");
|
|
178
|
+
botLean = Get<RotateTransform>("BotLean"); headRot = Get<RotateTransform>("HeadRot"); antRot = Get<RotateTransform>("AntennaRot");
|
|
179
|
+
botMove = Get<TranslateTransform>("BotMove"); headMove = Get<TranslateTransform>("HeadMove"); faceLook = Get<TranslateTransform>("FaceLook");
|
|
180
|
+
eyeLook = Get<TranslateTransform>("EyeLook"); scanY = Get<TranslateTransform>("ScanY");
|
|
181
|
+
${SCREENS.map((sc, i) => ` screens.Add(MakeScreen(${i}, ${n(sc.tilt)}, ${n(sc.turn)}, ${n(sc.look[0])}, ${n(sc.look[1])}, ${n(sc.head)}, ${n(sc.dwell[0])}, ${n(sc.dwell[1])}));`).join('\n')}
|
|
182
|
+
zzz = Get<System.Windows.UIElement>("Zzz"); screensView = Get<System.Windows.UIElement>("Screens");
|
|
183
|
+
alert = Get<System.Windows.UIElement>("Alert"); alertScale = Get<ScaleTransform>("AlertScale"); alertRot = Get<RotateTransform>("AlertRot"); alertMove = Get<TranslateTransform>("AlertMove");
|
|
184
|
+
think = Get<System.Windows.UIElement>("Think"); thinkScale = Get<ScaleTransform>("ThinkScale");
|
|
185
|
+
for (int i = 0; i < 3; i++) { var d = Get<System.Windows.UIElement>("ThinkDot" + i); var tt = new TranslateTransform(); d.RenderTransform = tt; thinkDots.Add(tt); thinkDotEls.Add(d); }
|
|
186
|
+
sparks = Get<System.Windows.UIElement>("Sparks");
|
|
187
|
+
propsScale = Get<ScaleTransform>("PropsScale"); propsLean = Get<RotateTransform>("PropsLean"); propsMove = Get<TranslateTransform>("PropsMove");
|
|
188
|
+
propsHeadRot = Get<RotateTransform>("PropsHeadRot"); propsHeadMove = Get<TranslateTransform>("PropsHeadMove");
|
|
189
|
+
for (int i = 0; i < SPARK_ANGLES.Length; i++) {
|
|
190
|
+
var sp = Get<System.Windows.UIElement>("Spark" + i); var g = new TransformGroup();
|
|
191
|
+
g.Children.Add(new ScaleTransform()); g.Children.Add(new RotateTransform()); g.Children.Add(new TranslateTransform());
|
|
192
|
+
sp.RenderTransform = g; sparkEls.Add(sp); sparkXf.Add(g);
|
|
193
|
+
}
|
|
194
|
+
for (int i = 0; i < 3; i++) { var z = Get<System.Windows.Controls.TextBlock>("Zzz" + i); z.RenderTransform = new ScaleTransform(); zs.Add(z); }
|
|
195
|
+
foreach (var name in new[] { ${BOT_BLINKS.map((b) => `"${b}"`).join(', ')} }) { var b = w.FindName(name) as ScaleTransform; if (b != null) blinks.Add(b); }
|
|
196
|
+
foreach (var name in new[] { ${BOT_SPINS.map((b) => `"${b}"`).join(', ')} }) { var r = w.FindName(name) as RotateTransform; if (r != null) spins.Add(r); }
|
|
197
|
+
faceBase = faceScale.ScaleX;
|
|
198
|
+
foreach (var name in new[] { ${BOT_EYES.map((e) => `"${e}"`).join(', ')} }) eyeEls[name] = new[] { Get<System.Windows.UIElement>("Eyes_" + name + "_L"), Get<System.Windows.UIElement>("Eyes_" + name + "_R") };
|
|
199
|
+
foreach (var name in new[] { ${BOT_MOUTHS.map((e) => `"${e}"`).join(', ')} }) mouthEls[name] = Get<System.Windows.UIElement>("Mouth_" + name);
|
|
200
|
+
eyeMorphL = Get<ScaleTransform>("EyeMorphL"); eyeMorphR = Get<ScaleTransform>("EyeMorphR"); mouthMorph = Get<ScaleTransform>("MouthMorph");
|
|
201
|
+
tint.Fill = tintBrush; halo.Fill = tintBrush;
|
|
202
|
+
tray = Get<System.Windows.UIElement>("Tray"); trayArrow = Get<System.Windows.UIElement>("TrayArrow"); trayBase = Get<System.Windows.UIElement>("TrayBase"); trayNo = Get<System.Windows.UIElement>("TrayNo");
|
|
203
|
+
trayDeny = Get<System.Windows.UIElement>("TrayDeny"); trayBadge = Get<System.Windows.UIElement>("TrayBadge");
|
|
204
|
+
trayScale = Get<ScaleTransform>("TrayScale"); trayBodyScale = Get<ScaleTransform>("TrayBodyScale"); trayBadgeScale = Get<ScaleTransform>("TrayBadgeScale");
|
|
205
|
+
trayFlapL = Get<RotateTransform>("TrayFlapL"); trayFlapR = Get<RotateTransform>("TrayFlapR"); trayBodyLean = Get<RotateTransform>("TrayBodyLean");
|
|
206
|
+
trayMove = Get<TranslateTransform>("TrayMove"); trayArrowMove = Get<TranslateTransform>("TrayArrowMove"); trayBodyMove = Get<TranslateTransform>("TrayBodyMove");
|
|
207
|
+
trayCount = Get<System.Windows.Controls.TextBlock>("TrayCount");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The tray in the bot's arms. "open" = files dragged near the bot: held up a bit bigger, lid flaps swing open, upload arrow bounces;
|
|
212
|
+
* "deny" = it cannot take them: lid shut, red cross, the box and the head shake; "hold" = dropped files wait for the next question:
|
|
213
|
+
* smaller, lid shut, count badge; "off" = put away (coming from "hold": handed over - lifts up while it shrinks). count = files
|
|
214
|
+
* waiting (the badge; it pops when the count goes up).
|
|
215
|
+
*/
|
|
216
|
+
public void Tray(string mode, int count) {
|
|
217
|
+
double t = Now;
|
|
218
|
+
if (mode != trayMode) {
|
|
219
|
+
if (mode == "open") { trayAt = t; perkAt = t; antA.V -= 120; }
|
|
220
|
+
else if (mode == "deny") { trayAt = t; shakeAt = t; }
|
|
221
|
+
else if (mode == "off" && trayMode == "hold") giveAt = t;
|
|
222
|
+
trayMode = mode;
|
|
223
|
+
}
|
|
224
|
+
if (count > trayN) badgePop.V += 9;
|
|
225
|
+
trayN = Math.Max(0, count); trayCount.Text = trayN > 99 ? "99+" : trayN.ToString();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Change the face (BOT_FACES eyes + mouth kind). The first face shows at once; later ones morph (see Frame) - calling again before a
|
|
230
|
+
* morph finished just retargets it, so a quick hover in / out never stacks up.
|
|
231
|
+
*/
|
|
232
|
+
public void SetFace(string eyes, string mouth) {
|
|
233
|
+
if (!eyeEls.ContainsKey(eyes) || !mouthEls.ContainsKey(mouth)) return;
|
|
234
|
+
if (eyesNow == null) { eyesNow = eyes; ShowEyes(eyes); }
|
|
235
|
+
else if (eyesNext != null || eyes != eyesNow) eyesNext = eyes;
|
|
236
|
+
if (mouthNow == null) { mouthNow = mouth; ShowMouth(mouth); }
|
|
237
|
+
else if (mouthNext != null || mouth != mouthNow) { if (mouthNext == null) mouthAt = Now + MOUTH_LAG; mouthNext = mouth; }
|
|
238
|
+
}
|
|
239
|
+
void ShowEyes(string name) {
|
|
240
|
+
foreach (var kv in eyeEls) { var v = kv.Key == name ? Visibility.Visible : Visibility.Collapsed; foreach (var e in kv.Value) e.Visibility = v; }
|
|
241
|
+
}
|
|
242
|
+
void ShowMouth(string name) {
|
|
243
|
+
foreach (var kv in mouthEls) kv.Value.Visibility = kv.Key == name ? Visibility.Visible : Visibility.Collapsed;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
Screen MakeScreen(int i, double tilt, double turn, double lookX, double lookY, double head, double dwellMin, double dwellMax) {
|
|
247
|
+
var sc = new Screen { El = Get<System.Windows.UIElement>("Scr" + i), Tilt = Get<System.Windows.Media.Media3D.AxisAngleRotation3D>("Scr" + i + "Tilt"), Turn = Get<System.Windows.Media.Media3D.AxisAngleRotation3D>("Scr" + i + "Turn"),
|
|
248
|
+
Float = Get<System.Windows.Media.Media3D.TranslateTransform3D>("Scr" + i + "Float"), Scroll = w.FindName("Scr" + i + "Scroll") as TranslateTransform,
|
|
249
|
+
RestTilt = tilt, RestTurn = turn, LookX = lookX, LookY = lookY, Head = head, DwellMin = dwellMin, DwellMax = dwellMax };
|
|
250
|
+
for (int k = 0; k < 3; k++) { var b = w.FindName("Scr" + i + "Bar" + k) as ScaleTransform; if (b != null) sc.Bars.Add(b); }
|
|
251
|
+
return sc;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public void Start() { CompositionTarget.Rendering += OnRender; }
|
|
255
|
+
public void Stop() { CompositionTarget.Rendering -= OnRender; clock.Stop(); }
|
|
256
|
+
/** Time of the current frame: gestures started by SetState line up with the frame clock (live or Tick). */
|
|
257
|
+
double Now { get { return now; } }
|
|
258
|
+
|
|
259
|
+
/** Pop in when the window first appears (overshooting scale) with a little antenna flick. */
|
|
260
|
+
public void Intro() { pop.X = 0.35; pop.V = 0; antA.V = 160; nextBlink = Now + 0.9; }
|
|
261
|
+
|
|
262
|
+
/** Doze off (the window calls this after a long idle) or wake up: wake = perk up, antenna flick, a blink. */
|
|
263
|
+
public void Doze(bool on) {
|
|
264
|
+
if (on == dozing) return;
|
|
265
|
+
dozing = on; m = Motion.For(on ? "doze" : state);
|
|
266
|
+
if (on) nextJerk = Now + 6 + rnd.NextDouble() * 5;
|
|
267
|
+
else { perkAt = Now; antA.V += 150; blinkAt = Now; }
|
|
268
|
+
}
|
|
269
|
+
public bool Dozing { get { return dozing; } }
|
|
270
|
+
|
|
271
|
+
public void SetState(string s, string color) {
|
|
272
|
+
double t = Now;
|
|
273
|
+
if (s != state) {
|
|
274
|
+
state = s; m = Motion.For(s); dozing = false;
|
|
275
|
+
stateAt = t; nextLife = t + 14 + rnd.NextDouble() * 10; askLevel = 0;
|
|
276
|
+
if (s == "done") sparkAt = t;
|
|
277
|
+
if (s == "working") { workAt = t; focus = 0; nextFocus = t + 2.4; }
|
|
278
|
+
switch (m.Enter) {
|
|
279
|
+
case "hop": hopAt = t; hopKick = landKick = false; flashAt = t; break;
|
|
280
|
+
case "shake": shakeAt = t; break;
|
|
281
|
+
case "nod": nodAt = t; break;
|
|
282
|
+
case "perk": perkAt = t; flashAt = t; break;
|
|
283
|
+
}
|
|
284
|
+
if (rnd.NextDouble() < 0.7) blinkAt = t; // a state change usually comes with a blink
|
|
285
|
+
}
|
|
286
|
+
if (!string.IsNullOrEmpty(color)) {
|
|
287
|
+
var c = (Color)ColorConverter.ConvertFromString(color);
|
|
288
|
+
if (!hasColor) { hasColor = true; colorFrom = colorTo = c; tintBrush.Color = c; }
|
|
289
|
+
else if (c != colorTo) { colorFrom = tintBrush.Color; colorTo = c; colorAt = Now; }
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* One-shot reactions that do not change the state: "dizzy" (shaken while dragged), "giggle" (clicked fast), "purr" (petted; call again
|
|
295
|
+
* while petting continues), "wave" (welcome back: hop + perk + flash).
|
|
296
|
+
*/
|
|
297
|
+
public void Play(string g) {
|
|
298
|
+
double t = Now;
|
|
299
|
+
switch (g) {
|
|
300
|
+
case "dizzy": dizzyAt = t; antA.V += 220; break;
|
|
301
|
+
case "giggle": giggleAt = t; antA.V -= 140; blinkAt = t; blushAt = t; break;
|
|
302
|
+
case "purr": purrUntil = t + 0.9; break;
|
|
303
|
+
case "wave": hopAt = t; hopKick = landKick = false; perkAt = t + 0.6; flashAt = t; blushAt = t; break;
|
|
304
|
+
case "wink": blinkAt = t; blushAt = t; antA.V -= 60; break;
|
|
305
|
+
// Busy -> needs you: a start (eyes pop wide, antenna jolts, a quick rise) before the waiting look.
|
|
306
|
+
case "startle": perkAt = t; flashAt = t; antA.V -= 260; eyeSq.V += 6; pop.V += 2.5; break;
|
|
307
|
+
// Done after an error: no hop - sag with a slow breath out, then perk up.
|
|
308
|
+
case "relief": hopAt = -10; sighAt = t; perkAt = t + 0.75; antA.V += 70; break;
|
|
309
|
+
// Done after long work: a second hop + sparkle burst right after the first.
|
|
310
|
+
case "cheer": hop2At = t + 0.62; break;
|
|
311
|
+
// Done after a quick task: a nod instead of the hop.
|
|
312
|
+
case "small": hopAt = -10; nodAt = t; break;
|
|
313
|
+
case "ack": nodAt = t; antA.V -= 80; break;
|
|
314
|
+
case "yawn": yawnAt = t; break;
|
|
315
|
+
// Files dropped into the tray: it gulps them (squash, lid snaps shut), a nod and a little sparkle.
|
|
316
|
+
case "gulp": gulpAt = t; nodAt = t + 0.12; sparkAt = t; antA.V += 110; break;
|
|
317
|
+
}
|
|
318
|
+
reactAt = t;
|
|
319
|
+
}
|
|
320
|
+
public bool Dizzy { get { return Now - dizzyAt < DIZZY_S; } }
|
|
321
|
+
/** Typing in the ask box: look at it (dx, dy = box offset from the bot, DIPs) for a moment; called again on each keystroke. */
|
|
322
|
+
public void Attend(double dx, double dy) {
|
|
323
|
+
attendUntil = Now + 1.4; attendX = Clamp(dx / 110, -1, 1) * 2.6; attendY = Clamp(dy / 110, -1, 1) * 2.0;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** The window was dragged by (dx, dy) DIPs: the body lags behind and the antenna swings. */
|
|
327
|
+
public void Nudge(double dx, double dy) {
|
|
328
|
+
dx = Math.Max(-40, Math.Min(40, dx));
|
|
329
|
+
lean.V -= dx * 4.0; antA.V -= dx * 14.0 + dy * 3.0;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
static double Ease(double current, double target, double rate, double dt) { return current + (target - current) * (1 - Math.Exp(-rate * dt)); }
|
|
333
|
+
static double Clamp(double v, double lo, double hi) { return v < lo ? lo : (v > hi ? hi : v); }
|
|
334
|
+
static double Bump(double u, double len) { return (u < 0 || u > len) ? 0 : Math.Sin(Math.PI * u / len); }
|
|
335
|
+
static Color Mix(Color a, Color b, double k) {
|
|
336
|
+
return Color.FromArgb((byte)(a.A + (b.A - a.A) * k), (byte)(a.R + (b.R - a.R) * k), (byte)(a.G + (b.G - a.G) * k), (byte)(a.B + (b.B - a.B) * k));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
void OnRender(object sender, EventArgs e) {
|
|
340
|
+
var re = e as RenderingEventArgs;
|
|
341
|
+
if (re != null) { if (re.RenderingTime == lastRender) return; lastRender = re.RenderingTime; }
|
|
342
|
+
if (!w.IsVisible) return;
|
|
343
|
+
double t = clock.Elapsed.TotalSeconds; double dt = Clamp(t - last, 0.001, 0.05); last = t; now = t;
|
|
344
|
+
try { Frame(t, dt); } catch { }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Drive one frame with an explicit clock (offscreen previews / tests). */
|
|
348
|
+
public void Tick(double t, double dt) { now = t; Frame(t, dt); }
|
|
349
|
+
|
|
350
|
+
void Frame(double t, double dt) {
|
|
351
|
+
// 1) Ease state values; phases accumulate so a frequency change never jumps.
|
|
352
|
+
amp = Ease(amp, m.Bob, 4, dt); breathe = Ease(breathe, m.Breathe, 4, dt);
|
|
353
|
+
headTilt = Ease(headTilt, m.HeadTilt, 5, dt); headY = Ease(headY, m.HeadY, 5, dt); antRest = Ease(antRest, m.Antenna, 3, dt);
|
|
354
|
+
glow = Ease(glow, m.Glow, 5, dt); glowPulse = Ease(glowPulse, m.GlowPulse, 5, dt);
|
|
355
|
+
tintV = Ease(tintV, m.Tint, 6, dt); tintPulse = Ease(tintPulse, m.TintPulse, 6, dt);
|
|
356
|
+
scan = Ease(scan, m.Scan, 4, dt); scale = Ease(scale, m.Scale, 6, dt); opacity = Ease(opacity, m.Opacity, 3, dt);
|
|
357
|
+
phase += TAU * m.BobHz * dt; glowPhase += TAU * Math.Max(0.1, m.GlowHz) * dt; tintPhase += TAU * Math.Max(0.1, m.TintHz) * dt; scanPhase += 0.62 * dt;
|
|
358
|
+
|
|
359
|
+
// 2) Body: bob + breathing, plus one-shot gestures.
|
|
360
|
+
double bob = Math.Sin(phase) * amp, bobVel = Math.Cos(phase) * amp * TAU * m.BobHz;
|
|
361
|
+
double sq = Math.Sin(phase) * breathe; double y = bob;
|
|
362
|
+
double hu = t - hopAt;
|
|
363
|
+
if (hu >= 0 && hu < 0.58) {
|
|
364
|
+
if (hu < 0.09) sq -= 0.075 * Math.Sin(hu / 0.09 * Math.PI / 2);
|
|
365
|
+
else if (hu < 0.43) { double k = (hu - 0.09) / 0.34; y -= 5.0 * Math.Sin(k * Math.PI); sq += 0.05 * (1 - k); if (!hopKick) { hopKick = true; antA.V -= 120; } }
|
|
366
|
+
else { double k = (hu - 0.43) / 0.15; sq -= 0.065 * Math.Sin(k * Math.PI); if (!landKick) { landKick = true; antA.V += 190; headA.V -= 30; } }
|
|
367
|
+
}
|
|
368
|
+
if (state == "waiting" && t - perkAt > 2.6) perkAt = t;
|
|
369
|
+
double perk = Bump(t - perkAt, 0.42);
|
|
370
|
+
y -= perk * 2.6; sq += perk * 0.03;
|
|
371
|
+
if (hop2At > 0 && t >= hop2At) { hop2At = -10; hopAt = t; hopKick = landKick = false; sparkAt = t; flashAt = t; }
|
|
372
|
+
// Relief: sink + squash slowly (a breath out); yawn: stretch up.
|
|
373
|
+
double sigh = Bump(t - sighAt, 0.8), yawn = Bump(t - yawnAt, 1.8);
|
|
374
|
+
y += sigh * 2.4; sq -= sigh * 0.035; sq += yawn * 0.035;
|
|
375
|
+
// Play: dizzy / giggle fade out over their length; purr eases in and out while petting goes on.
|
|
376
|
+
double dizU = t - dizzyAt, dz = (dizU >= 0 && dizU < DIZZY_S) ? 1 - dizU / DIZZY_S : 0;
|
|
377
|
+
double gigU = t - giggleAt, gig = (gigU >= 0 && gigU < GIGGLE_S) ? 1 - gigU / GIGGLE_S : 0;
|
|
378
|
+
purrK = Ease(purrK, t < purrUntil ? 1 : 0, 4, dt);
|
|
379
|
+
y -= Math.Abs(Math.Sin(gigU * 26)) * 2.4 * gig; sq += Math.Sin(gigU * 26) * 0.02 * gig + Math.Sin(t * 2.2) * 0.012 * purrK;
|
|
380
|
+
press.Step(Pressed ? 1 : 0, 420, 32, dt); hover.Step(Hover ? 1 : 0, 140, 22, dt); pop.Step(1, 170, 11, dt);
|
|
381
|
+
double sy = 1 + sq - press.X * 0.07, sx = 1 - sq * 0.6 + press.X * 0.05;
|
|
382
|
+
double s = pop.X * scale * (1 + hover.X * 0.035);
|
|
383
|
+
botScale.ScaleX = s * sx; botScale.ScaleY = s * sy;
|
|
384
|
+
botMove.Y = y; botMove.X = 0;
|
|
385
|
+
lean.Step(m.Lean, 60, 10, dt);
|
|
386
|
+
if (Math.Abs(lean.X) > LEAN_MAX) { lean.X = Math.Sign(lean.X) * LEAN_MAX; lean.V = -lean.V * 0.3; }
|
|
387
|
+
botLean.Angle = lean.X;
|
|
388
|
+
bot.Opacity = opacity;
|
|
389
|
+
double up = Math.Max(0, -y);
|
|
390
|
+
shadowScale.ScaleX = Clamp(s * (1 - up * 0.035), 0.6, 1.2); shadowScale.ScaleY = shadowScale.ScaleX;
|
|
391
|
+
shadow.Opacity = Clamp(1 - up * 0.06, 0.4, 1) * opacity;
|
|
392
|
+
|
|
393
|
+
// 3) Eyes: cursor when near (anywhere on screen), else the state's gaze or idle glances; saccade-fast spring.
|
|
394
|
+
double cx = 0, cy = 0, nearT = 0;
|
|
395
|
+
if (!Dragging && PresentationSource.FromVisual(face) != null) {
|
|
396
|
+
POINT p; if (GetCursorPos(out p)) {
|
|
397
|
+
var src = PresentationSource.FromVisual(w); double dpi = src != null && src.CompositionTarget != null ? src.CompositionTarget.TransformToDevice.M11 : 1;
|
|
398
|
+
var fc = face.PointToScreen(new System.Windows.Point(0, 0));
|
|
399
|
+
double dx = (p.X - fc.X) / dpi, dy = (p.Y - fc.Y) / dpi, d = Math.Sqrt(dx * dx + dy * dy);
|
|
400
|
+
// The cursor just moved (the owner, or the agent driving the mouse): the eyes dart after it wherever it is on screen, for a
|
|
401
|
+
// moment after it stops; a still cursor is only watched when near. Working: a little less (the screens still pull the eyes).
|
|
402
|
+
if (p.X != curX || p.Y != curY) { curX = p.X; curY = p.Y; curMovedAt = t; }
|
|
403
|
+
double moving = Clamp(1 - (t - curMovedAt - 1.5), 0, 1);
|
|
404
|
+
// Working: the eyes stay on the screens (darting between them) - only the pointer on the bot itself draws them away.
|
|
405
|
+
nearT = Hover ? 1 : (state == "working" ? 0 : Math.Max(Clamp((460 - d) / 160, 0, 1), moving));
|
|
406
|
+
// Keep the real direction (per-axis clamping pinned every diagonal to the corner); full swing from 140 DIPs out.
|
|
407
|
+
double g = Math.Min(1, d / 140) / Math.Max(d, 0.001);
|
|
408
|
+
cx = dx * g * 2.6; cy = dy * g * 2.0;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
near.Step(nearT, 60, 15, dt);
|
|
412
|
+
// Dozing: now and then a startled jerk (head snaps up, antenna flicks) before nodding off again.
|
|
413
|
+
if (dozing && t >= nextJerk) { perkAt = t; antA.V -= 130; nextJerk = t + 7 + rnd.NextDouble() * 6; }
|
|
414
|
+
bool asleep = state == "paused" || state == "offline" || dozing;
|
|
415
|
+
double gx, gy;
|
|
416
|
+
// Working: eyes on the focused screen. Main screen = reading (sweep along a line, snap back); side screens = a short steady look.
|
|
417
|
+
if (state == "working") {
|
|
418
|
+
if (t >= nextFocus) {
|
|
419
|
+
// Next screen: one of the other two (all three get looked at, never the same one twice in a row).
|
|
420
|
+
focus = (focus + 1 + rnd.Next(2)) % screens.Count; var f = screens[focus];
|
|
421
|
+
nextFocus = t + f.DwellMin + rnd.NextDouble() * (f.DwellMax - f.DwellMin); if (rnd.NextDouble() < 0.4) blinkAt = t;
|
|
422
|
+
}
|
|
423
|
+
var fs = screens[focus];
|
|
424
|
+
if (focus == 0) { double ru = (t * 0.55) % 1.0; gx = fs.LookX + (ru < 0.82 ? -2.2 + 4.4 * (ru / 0.82) : 2.2 - 4.4 * ((ru - 0.82) / 0.18)); }
|
|
425
|
+
else gx = fs.LookX + Math.Sin(t * 3.1) * 0.35;
|
|
426
|
+
gy = fs.LookY;
|
|
427
|
+
}
|
|
428
|
+
else if (m.HasLook) { gx = m.LookX + Math.Sin(t * 0.9) * 0.3; gy = m.LookY; }
|
|
429
|
+
else {
|
|
430
|
+
if (t >= nextGlance) {
|
|
431
|
+
if (rnd.NextDouble() < 0.5) { glanceX = 0; glanceY = 0; } else { glanceX = (rnd.NextDouble() * 2 - 1) * 2.2; glanceY = (rnd.NextDouble() * 2 - 1) * 1.3; }
|
|
432
|
+
nextGlance = t + 1.4 + rnd.NextDouble() * 3.4; if (rnd.NextDouble() < 0.3) blinkAt = t;
|
|
433
|
+
}
|
|
434
|
+
gx = glanceX; gy = glanceY;
|
|
435
|
+
}
|
|
436
|
+
if (asleep) { gx = 0; gy = 0; }
|
|
437
|
+
double nw = asleep ? 0 : near.X;
|
|
438
|
+
// Dizzy: eyes roll round and round instead of following the cursor.
|
|
439
|
+
if (dz > 0) { gx = Math.Cos(dizU * 8) * 2.4 * dz; gy = Math.Sin(dizU * 8) * 1.6 * dz; nw = 0; }
|
|
440
|
+
// Waiting "ask": look at the cursor wherever it is; typing in the ask box: look at the box.
|
|
441
|
+
double ask = Bump(t - askAt, 1.8);
|
|
442
|
+
if (!asleep) nw = Math.Max(nw, ask);
|
|
443
|
+
if (t < attendUntil && !asleep && dz <= 0) { gx = attendX; gy = attendY; nw = 0; }
|
|
444
|
+
lookX.Step(gx + (cx - gx) * nw, 320, 34, dt); lookY.Step(gy + (cy - gy) * nw, 320, 34, dt);
|
|
445
|
+
eyeLook.X = lookX.X; eyeLook.Y = lookY.X;
|
|
446
|
+
faceLook.X = lookX.X * 0.55; faceLook.Y = lookY.X * 0.45;
|
|
447
|
+
|
|
448
|
+
// 4) Head: spring toward the state's tilt + a curious lean toward a nearby cursor; lags the body's bob; nod / shake gestures.
|
|
449
|
+
double curious = asleep ? 0 : Clamp(cx / 2.6, -1, 1) * 3.0 * near.X;
|
|
450
|
+
headFocus = Ease(headFocus, state == "working" ? screens[focus].Head : 0, 5, dt);
|
|
451
|
+
headA.Step(headTilt + curious + headFocus + purrK * 7 + askSide * (5 + 2 * askLevel) * ask - yawn * 7, 95, 12, dt);
|
|
452
|
+
double su = t - shakeAt, shake = (su >= 0 && su < 0.8) ? 7 * Math.Exp(-su * 4.2) * Math.Sin(su * 27) : 0;
|
|
453
|
+
double angle = headA.X + shake + Math.Sin(dizU * 7) * 9 * dz + Math.Sin(gigU * 30) * 3 * gig;
|
|
454
|
+
headRot.Angle = angle;
|
|
455
|
+
double squint = Bump(t - squintAt, 0.9);
|
|
456
|
+
headMove.Y = headY - bobVel * 0.13 + Bump(t - nodAt, 0.5) * 2.2 - perk * 0.8 + squint * 0.8;
|
|
457
|
+
double headVel = (angle - prevHead) / dt; headAcc += ((headVel - prevHeadVel) / dt - headAcc) * 0.5; prevHead = angle; prevHeadVel = headVel;
|
|
458
|
+
double faceS = faceBase * (1 + perk * 0.05 + Bump(t - flashAt, 0.35) * 0.04);
|
|
459
|
+
faceScale.ScaleX = faceS; faceScale.ScaleY = faceS;
|
|
460
|
+
// Props (zzz / "!" / thought bubble / sparkles) ride on the head: same head + body transforms, so they follow drags, leans and bobs.
|
|
461
|
+
propsHeadRot.Angle = angle; propsHeadMove.X = headMove.X; propsHeadMove.Y = headMove.Y;
|
|
462
|
+
propsScale.ScaleX = botScale.ScaleX; propsScale.ScaleY = botScale.ScaleY; propsLean.Angle = botLean.Angle;
|
|
463
|
+
propsMove.X = botMove.X; propsMove.Y = botMove.Y;
|
|
464
|
+
|
|
465
|
+
// 5) Antenna: loose spring, pushed by the head's angular acceleration and gestures (see hop / Nudge); a slow idle sway.
|
|
466
|
+
antA.V -= Clamp(headAcc, -4000, 4000) * 0.55 * dt;
|
|
467
|
+
antA.Step(antRest + Math.Sin(phase * 0.5 + 1.3) * 1.2 + Math.Sin(t * 3) * 8 * purrK, 150, 5.5, dt);
|
|
468
|
+
antA.X = Clamp(antA.X, -28, 28); antRot.Angle = antA.X;
|
|
469
|
+
|
|
470
|
+
// 6) Lights: ear glow (alternating while working), antenna tint pulse, flash on done / attention, visor scan.
|
|
471
|
+
double flash = (t - flashAt >= 0 && t - flashAt < 1.2) ? Math.Exp(-(t - flashAt) * 3.2) * 0.8 : 0;
|
|
472
|
+
double gl = glow + glowPulse * Math.Sin(glowPhase) + flash, gr = glow + glowPulse * Math.Sin(glowPhase + (m.Alt ? Math.PI : 0)) + flash;
|
|
473
|
+
earL.Opacity = Clamp(gl, 0, 1); earR.Opacity = Clamp(gr, 0, 1);
|
|
474
|
+
double tv = Clamp(tintV + tintPulse * Math.Sin(tintPhase), 0, 1);
|
|
475
|
+
double cu = (t - colorAt) / COLOR_S;
|
|
476
|
+
if (cu >= 0 && cu < 1) { double k = cu * cu * (3 - 2 * cu); tintBrush.Color = Mix(colorFrom, colorTo, k); }
|
|
477
|
+
else if (hasColor && tintBrush.Color != colorTo) tintBrush.Color = colorTo;
|
|
478
|
+
tint.Opacity = tv; halo.Opacity = Clamp(0.12 + (tv - 0.45) * 0.9 + flash * 0.5, 0, 0.8);
|
|
479
|
+
visorFx.Opacity = scan; scanY.Y = (scanPhase % 1.0) * VISOR_SCAN;
|
|
480
|
+
double blush = Math.Max(purrK * 0.9, Bump(t - blushAt, 1.8) * 0.85); if (blushL != null) blushL.Opacity = blush; if (blushR != null) blushR.Opacity = blush;
|
|
481
|
+
|
|
482
|
+
// 7) Screens (working): flip up from edge-on one after another with a little overshoot, drift, the focused one lights up;
|
|
483
|
+
// text scrolls / bars bounce. Collapsed when folded away (no 3D work). Zzz (offline): letters drift up and fade.
|
|
484
|
+
bool working = state == "working", shown = working;
|
|
485
|
+
for (int i = 0; i < screens.Count; i++) {
|
|
486
|
+
var sc = screens[i];
|
|
487
|
+
sc.Pop.Step(working && t - workAt > i * 0.14 ? 1 : 0, 160, 13, dt);
|
|
488
|
+
double sp = sc.Pop.X;
|
|
489
|
+
if (sp > 0.02) shown = true;
|
|
490
|
+
sc.Lit = Ease(sc.Lit, working && i == focus ? 1 : 0, 6, dt);
|
|
491
|
+
sc.El.Opacity = Clamp(sp, 0, 1) * (0.68 + 0.32 * sc.Lit);
|
|
492
|
+
sc.Tilt.Angle = sc.RestTilt + (1 - sp) * (90 - sc.RestTilt);
|
|
493
|
+
sc.Turn.Angle = sc.RestTurn + Math.Sin(t * 0.6 + i * 2.1) * 5;
|
|
494
|
+
sc.Float.OffsetY = Math.Sin(t * 1.3 + i * 1.7) * 1.2;
|
|
495
|
+
if (sc.Scroll != null) sc.Scroll.Y = -((t * (4 + 5 * sc.Lit) + i * 7) % SCREEN_LOOP);
|
|
496
|
+
for (int k = 0; k < sc.Bars.Count; k++) sc.Bars[k].ScaleY = 0.3 + 0.7 * Math.Abs(Math.Sin(t * (1.3 + k * 0.5) + k * 1.9));
|
|
497
|
+
}
|
|
498
|
+
var sv = shown ? Visibility.Visible : Visibility.Collapsed; if (screensView.Visibility != sv) screensView.Visibility = sv;
|
|
499
|
+
sleep = Ease(sleep, state == "offline" || dozing ? 1 : 0, 2.5, dt); zzz.Opacity = sleep;
|
|
500
|
+
if (sleep > 0.01) {
|
|
501
|
+
for (int i = 0; i < zs.Count; i++) {
|
|
502
|
+
double u = (t / 2.8 + i / 3.0) % 1.0; var z = zs[i];
|
|
503
|
+
System.Windows.Controls.Canvas.SetLeft(z, ${n(Z.x)} + u * ${n(Z.dx)} + Math.Sin(u * TAU) * 3);
|
|
504
|
+
System.Windows.Controls.Canvas.SetTop(z, ${n(Z.y)} + u * ${n(Z.dy)});
|
|
505
|
+
var zsc = (ScaleTransform)z.RenderTransform; zsc.ScaleX = zsc.ScaleY = 0.45 + u * 0.7;
|
|
506
|
+
z.Opacity = u < 0.18 ? u / 0.18 : (u > 0.65 ? (1 - u) / 0.35 : 1);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// 8) Props. "!" (waiting): pops in, hops + wiggles on each attention perk. Thought bubble (thinking): dots hop one after another.
|
|
511
|
+
// Sparkles (done): a one-shot burst out from the head, growing then shrinking, spinning.
|
|
512
|
+
alertPop.Step(state == "waiting" ? 1 : 0, 260, 13, dt);
|
|
513
|
+
double ap = Clamp(alertPop.X, 0, 1.4);
|
|
514
|
+
alert.Opacity = Clamp(alertPop.X, 0, 1);
|
|
515
|
+
if (ap > 0.001) {
|
|
516
|
+
alertScale.ScaleX = ap; alertScale.ScaleY = ap;
|
|
517
|
+
double pk = Bump(t - perkAt, 0.42);
|
|
518
|
+
alertMove.Y = -pk * 7 + Math.Sin(t * 2.2) * 0.8; alertRot.Angle = Math.Sin((t - perkAt) * 22) * 12 * pk;
|
|
519
|
+
}
|
|
520
|
+
thinkPop.Step(state == "thinking" ? 1 : 0, 200, 15, dt);
|
|
521
|
+
double tp = Clamp(thinkPop.X, 0, 1.3);
|
|
522
|
+
think.Opacity = Clamp(thinkPop.X, 0, 1);
|
|
523
|
+
if (tp > 0.001) {
|
|
524
|
+
thinkScale.ScaleX = tp; thinkScale.ScaleY = tp;
|
|
525
|
+
for (int i = 0; i < thinkDots.Count; i++) {
|
|
526
|
+
double du = (t * 1.5 - i * 0.2) % 1.0, hop = Bump(du, 0.34);
|
|
527
|
+
thinkDots[i].Y = -hop * 3.6; thinkDotEls[i].Opacity = 0.4 + 0.6 * hop;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
double su2 = t - sparkAt;
|
|
531
|
+
if (su2 >= 0 && su2 < 1.1) {
|
|
532
|
+
if (sparks.Visibility != Visibility.Visible) sparks.Visibility = Visibility.Visible;
|
|
533
|
+
double k = su2 / 1.1, e = 1 - Math.Pow(1 - k, 3), d = ${n(SP.from)} + (${n(SP.to)} - ${n(SP.from)}) * e;
|
|
534
|
+
for (int i = 0; i < sparkEls.Count; i++) {
|
|
535
|
+
double a = SPARK_ANGLES[i] * Math.PI / 180, sz = Bump(su2, 1.1) * (i % 2 == 0 ? 1.7 : 1.15);
|
|
536
|
+
var g = sparkXf[i];
|
|
537
|
+
var sc = (ScaleTransform)g.Children[0]; sc.ScaleX = sz; sc.ScaleY = sz;
|
|
538
|
+
((RotateTransform)g.Children[1]).Angle = k * 140 * (i % 2 == 0 ? 1 : -1);
|
|
539
|
+
var tr = (TranslateTransform)g.Children[2]; tr.X = ${n(SP.x)} + Math.Cos(a) * d; tr.Y = ${n(SP.y)} + Math.Sin(a) * d;
|
|
540
|
+
}
|
|
541
|
+
} else if (sparks.Visibility == Visibility.Visible) sparks.Visibility = Visibility.Collapsed;
|
|
542
|
+
|
|
543
|
+
// 9) Blink (random interval, sometimes double) and small mouth life.
|
|
544
|
+
if (t >= nextBlink) { blinkAt = t; doubleBlink = rnd.NextDouble() < 0.2; nextBlink = t + 2.3 + rnd.NextDouble() * 3.8; }
|
|
545
|
+
double bu = t - blinkAt; if (doubleBlink && bu > 0.22) bu -= 0.22;
|
|
546
|
+
double blink = 1;
|
|
547
|
+
if (bu >= 0 && bu < 0.17) blink = bu < 0.06 ? 1 - 0.9 * (bu / 0.06) : (bu < 0.08 ? 0.1 : 0.1 + 0.9 * Math.Sin((bu - 0.08) / 0.09 * Math.PI / 2));
|
|
548
|
+
foreach (var b in blinks) b.ScaleY = blink;
|
|
549
|
+
if (dz > 0) foreach (var r in spins) r.Angle = (dizU * 540) % 360;
|
|
550
|
+
|
|
551
|
+
// 10) Face morph: eyes squash shut fast (~80 ms, no overshoot), swap kind while shut, spring open with a small overshoot (and a
|
|
552
|
+
// touch wider while squashed); the mouth a beat later shrinks, swaps, pops back a little bouncier.
|
|
553
|
+
bool eyeSwap = eyesNext != null;
|
|
554
|
+
eyeSq.Step(eyeSwap ? 0 : 1, eyeSwap ? 1400 : 380, eyeSwap ? 75 : 20, dt);
|
|
555
|
+
if (eyeSwap && eyeSq.X < 0.2) { eyesNow = eyesNext; eyesNext = null; ShowEyes(eyesNow); }
|
|
556
|
+
double es = Clamp(eyeSq.X, 0.08, 1.25) * (1 - 0.38 * squint);
|
|
557
|
+
eyeMorphL.ScaleY = es; eyeMorphR.ScaleY = es;
|
|
558
|
+
eyeMorphL.ScaleX = eyeMorphR.ScaleX = 1 + (1 - Math.Min(es, 1)) * 0.15;
|
|
559
|
+
bool mouthSwap = mouthNext != null && t >= mouthAt;
|
|
560
|
+
mouthSq.Step(mouthSwap ? 0 : 1, mouthSwap ? 1400 : 300, mouthSwap ? 75 : 15, dt);
|
|
561
|
+
if (mouthSwap && mouthSq.X < 0.3) { mouthNow = mouthNext; mouthNext = null; ShowMouth(mouthNow); }
|
|
562
|
+
double ms = Clamp(mouthSq.X, 0.15, 1.3) * (1 + 0.6 * Bump(t - yawnAt - 0.15, 1.5));
|
|
563
|
+
mouthMorph.ScaleX = ms; mouthMorph.ScaleY = ms;
|
|
564
|
+
|
|
565
|
+
// 11) Life in a long state: a rare gesture of its own - never while the pointer is on the bot, dragging, dozing or right after a
|
|
566
|
+
// reaction. Working a while: a focused squint or an "I see" nod. Waiting a while: tilt the head at the cursor as if asking, a bit
|
|
567
|
+
// more each time (capped) with a perk from the second time on.
|
|
568
|
+
if (t >= nextLife) {
|
|
569
|
+
nextLife = t + 22 + rnd.NextDouble() * 20;
|
|
570
|
+
double inState = t - stateAt;
|
|
571
|
+
if (!Hover && !Dragging && !dozing && t - reactAt > 6) {
|
|
572
|
+
if (state == "working" && inState > 15) { if (rnd.NextDouble() < 0.5) squintAt = t; else nodAt = t; }
|
|
573
|
+
else if (state == "waiting" && inState > 12) {
|
|
574
|
+
askAt = t; askSide = rnd.NextDouble() < 0.5 ? -1 : 1; askLevel = Math.Min(askLevel + 1, 3);
|
|
575
|
+
if (askLevel >= 2) perkAt = t + 0.3;
|
|
576
|
+
SetFace("curious", "hmm");
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
if (state == "waiting" && t - askAt >= 2.0 && eyesNow == "curious" && eyesNext == null) SetFace("wide", "open");
|
|
581
|
+
mouthOpen.ScaleY = 1 + Math.Sin(t * 3.4) * 0.1; mouthOpen.ScaleX = 1 - Math.Sin(t * 3.4) * 0.05;
|
|
582
|
+
talk.ScaleY = 0.45 + 0.55 * Math.Abs(Math.Sin(t * 12));
|
|
583
|
+
|
|
584
|
+
// 12) Tray: pops up in front of the body (rides its bob / lean / squash), held up while files hover near; the lid flutters open, the
|
|
585
|
+
// arrow bounces; a drop gulps (squash + lid snaps shut); a refusal shakes the box; handed over = lifts up as it shrinks away.
|
|
586
|
+
bool open = trayMode == "open";
|
|
587
|
+
trayPop.Step(open ? 1.06 : trayMode == "deny" ? 1 : trayMode == "hold" ? 0.9 : 0, 230, 17, dt);
|
|
588
|
+
double tpv = Math.Max(0, trayPop.X);
|
|
589
|
+
var tvis = tpv > 0.01 ? Visibility.Visible : Visibility.Collapsed; if (tray.Visibility != tvis) tray.Visibility = tvis;
|
|
590
|
+
if (tpv > 0.01) {
|
|
591
|
+
trayBodyScale.ScaleX = botScale.ScaleX; trayBodyScale.ScaleY = botScale.ScaleY; trayBodyLean.Angle = botLean.Angle;
|
|
592
|
+
trayBodyMove.X = botMove.X; trayBodyMove.Y = botMove.Y;
|
|
593
|
+
double gulp = Bump(t - gulpAt, 0.32);
|
|
594
|
+
trayScale.ScaleX = tpv * (1 + gulp * 0.14); trayScale.ScaleY = tpv * (1 - gulp * 0.2);
|
|
595
|
+
double du = t - trayAt, jolt = trayMode == "deny" && du < 0.7 ? Math.Exp(-du * 5) * Math.Sin(du * 42) * 6 : 0;
|
|
596
|
+
double give = trayMode == "off" ? Clamp((t - giveAt) / 0.4, 0, 1) : 0;
|
|
597
|
+
trayMove.X = jolt; trayMove.Y = (open ? -3 + Math.Sin(t * 4.2) * 1.6 : 0) - give * 34;
|
|
598
|
+
tray.Opacity = Clamp(tpv, 0, 1);
|
|
599
|
+
trayLid.Step(open ? 1 : 0, open ? 140 : 520, open ? 9 : 34, dt);
|
|
600
|
+
double lid = trayLid.X * LID_OPEN + (open ? Math.Sin(t * 9) * 7 * trayLid.X : 0);
|
|
601
|
+
trayFlapL.Angle = -lid; trayFlapR.Angle = lid;
|
|
602
|
+
denyK = Ease(denyK, trayMode == "deny" ? 1 : 0, 12, dt);
|
|
603
|
+
trayDeny.Opacity = denyK * 0.16; trayNo.Opacity = denyK; trayArrow.Opacity = trayBase.Opacity = 1 - denyK;
|
|
604
|
+
trayArrowMove.Y = open ? -Math.Abs(Math.Sin(t * 5.5)) * 8 : 0;
|
|
605
|
+
badgePop.Step(trayN > 0 ? 1 : 0, 320, 13, dt);
|
|
606
|
+
double bp = Clamp(badgePop.X, 0, 1.5);
|
|
607
|
+
trayBadge.Opacity = Clamp(bp, 0, 1); trayBadgeScale.ScaleX = bp; trayBadgeScale.ScaleY = bp;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
`;
|
|
612
|
+
|
|
613
|
+
/** Tham chiếu biên dịch cho khối C# (WPF) — PowerShell 5 cần đường dẫn đầy đủ của assembly. */
|
|
614
|
+
export const RIG_REFERENCES_PS = '([Windows.UIElement].Assembly.Location), ([Windows.Window].Assembly.Location), ([Windows.DependencyObject].Assembly.Location), ([System.Xaml.XamlSchemaContext].Assembly.Location)';
|