cc-pets 0.2.12 → 0.2.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/CHANGELOG.md +1 -1
- package/README.md +2 -1
- package/Sources/CCPets/main.m +62 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -63,7 +63,8 @@ Claude Code Hook 会合并到 `~/.claude/settings.json`,现有的 `env`、`mod
|
|
|
63
63
|
`~/.codex/pets/<name>/` 查找同名桌宠的 `spritesheet.webp` 或 `spritesheet.png`。
|
|
64
64
|
外部素材遵循 Codex 桌面端的 `spriteVersionNumber` 协议:字段缺失或为 `1` 时按
|
|
65
65
|
`1536×1872`、`8×9` 网格解析;为 `2` 时按 `1536×2288`、`8×11` 网格解析。
|
|
66
|
-
v2
|
|
66
|
+
v2 新增的最后两行用于十六向鼠标跟随;只在桌宠空闲时启用,拖动、悬停互动和
|
|
67
|
+
Agent 状态动画会优先播放。
|
|
67
68
|
|
|
68
69
|
交互区域存在重叠时,按“口袋、头部、脚部、身体左右侧”的优先级识别。拖动超过
|
|
69
70
|
3 像素后才进入拖动状态,避免普通点击被误判为拖动。
|
package/Sources/CCPets/main.m
CHANGED
|
@@ -268,6 +268,7 @@ static NSDictionary *LatestUsage(void) {
|
|
|
268
268
|
@interface PetView : NSView
|
|
269
269
|
@property NSImage *sheet;
|
|
270
270
|
@property NSInteger spriteRowCount;
|
|
271
|
+
@property NSInteger lookDirection;
|
|
271
272
|
@property NSInteger frameIndex;
|
|
272
273
|
@property NSInteger rowIndex;
|
|
273
274
|
@property NSArray<NSNumber *> *frames;
|
|
@@ -278,6 +279,8 @@ static NSDictionary *LatestUsage(void) {
|
|
|
278
279
|
@property NSPoint dragStartMouse;
|
|
279
280
|
@property NSPoint dragStartWindowOrigin;
|
|
280
281
|
@property NSString *currentPetID;
|
|
282
|
+
@property id globalMouseMonitor;
|
|
283
|
+
@property id localMouseMonitor;
|
|
281
284
|
@property(copy) void (^pocketHoverChanged)(BOOL hovering);
|
|
282
285
|
@property(copy) void (^positionChanged)(void);
|
|
283
286
|
@property(copy) void (^dragStateChanged)(BOOL dragging);
|
|
@@ -290,6 +293,7 @@ static NSDictionary *LatestUsage(void) {
|
|
|
290
293
|
if ((self = [super initWithFrame:frame])) {
|
|
291
294
|
_sheet = sheet;
|
|
292
295
|
_spriteRowCount = rowCount;
|
|
296
|
+
_lookDirection = -1;
|
|
293
297
|
_frames = @[@0, @1, @2, @3, @4, @5];
|
|
294
298
|
[NSTimer scheduledTimerWithTimeInterval:0.22 target:self
|
|
295
299
|
selector:@selector(nextFrame:) userInfo:nil repeats:YES];
|
|
@@ -298,9 +302,63 @@ static NSDictionary *LatestUsage(void) {
|
|
|
298
302
|
NSTrackingActiveAlways | NSTrackingInVisibleRect
|
|
299
303
|
owner:self userInfo:nil];
|
|
300
304
|
[self addTrackingArea:tracking];
|
|
305
|
+
[self updateLookTracking];
|
|
301
306
|
}
|
|
302
307
|
return self;
|
|
303
308
|
}
|
|
309
|
+
- (void)dealloc {
|
|
310
|
+
[self stopLookTracking];
|
|
311
|
+
}
|
|
312
|
+
- (void)startLookTracking {
|
|
313
|
+
if (self.spriteRowCount != 11 || self.globalMouseMonitor || self.localMouseMonitor) return;
|
|
314
|
+
__weak PetView *weakSelf = self;
|
|
315
|
+
self.globalMouseMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSEventMaskMouseMoved
|
|
316
|
+
handler:^(NSEvent *event) {
|
|
317
|
+
[weakSelf updateLookForScreenPoint:NSEvent.mouseLocation];
|
|
318
|
+
}];
|
|
319
|
+
self.localMouseMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskMouseMoved
|
|
320
|
+
handler:^NSEvent *(NSEvent *event) {
|
|
321
|
+
[weakSelf updateLookForScreenPoint:NSEvent.mouseLocation];
|
|
322
|
+
return event;
|
|
323
|
+
}];
|
|
324
|
+
}
|
|
325
|
+
- (void)stopLookTracking {
|
|
326
|
+
if (self.globalMouseMonitor) {
|
|
327
|
+
[NSEvent removeMonitor:self.globalMouseMonitor];
|
|
328
|
+
self.globalMouseMonitor = nil;
|
|
329
|
+
}
|
|
330
|
+
if (self.localMouseMonitor) {
|
|
331
|
+
[NSEvent removeMonitor:self.localMouseMonitor];
|
|
332
|
+
self.localMouseMonitor = nil;
|
|
333
|
+
}
|
|
334
|
+
self.lookDirection = -1;
|
|
335
|
+
}
|
|
336
|
+
- (void)updateLookTracking {
|
|
337
|
+
if (self.spriteRowCount == 11) [self startLookTracking];
|
|
338
|
+
else [self stopLookTracking];
|
|
339
|
+
}
|
|
340
|
+
- (void)updateLookForScreenPoint:(NSPoint)screenPoint {
|
|
341
|
+
if (self.spriteRowCount != 11 || self.draggingPet || self.oneShot || self.agentActive || !self.window) return;
|
|
342
|
+
|
|
343
|
+
NSPoint windowPoint = [self.window convertPointFromScreen:screenPoint];
|
|
344
|
+
NSPoint localPoint = [self convertPoint:windowPoint fromView:nil];
|
|
345
|
+
if (NSPointInRect(localPoint, self.bounds)) return;
|
|
346
|
+
|
|
347
|
+
NSPoint center = [self convertPoint:NSMakePoint(NSMidX(self.bounds), NSMidY(self.bounds)) toView:nil];
|
|
348
|
+
center = [self.window convertPointToScreen:center];
|
|
349
|
+
CGFloat dx = screenPoint.x - center.x;
|
|
350
|
+
CGFloat dy = screenPoint.y - center.y;
|
|
351
|
+
if (hypot(dx, dy) <= 1.0) return;
|
|
352
|
+
|
|
353
|
+
CGFloat degrees = fmod(atan2(dx, dy) * 180.0 / M_PI + 360.0, 360.0);
|
|
354
|
+
NSInteger direction = ((NSInteger)llround(degrees / 22.5)) % 16;
|
|
355
|
+
if (direction == self.lookDirection) return;
|
|
356
|
+
|
|
357
|
+
self.lookDirection = direction;
|
|
358
|
+
self.rowIndex = 9 + direction / 8;
|
|
359
|
+
self.frameIndex = direction % 8;
|
|
360
|
+
self.needsDisplay = YES;
|
|
361
|
+
}
|
|
304
362
|
- (NSArray<NSNumber *> *)framesFromZeroThrough:(NSInteger)last {
|
|
305
363
|
NSMutableArray<NSNumber *> *result = [NSMutableArray arrayWithCapacity:last + 1];
|
|
306
364
|
for (NSInteger index = 0; index <= last; index++) [result addObject:@(index)];
|
|
@@ -308,6 +366,7 @@ static NSDictionary *LatestUsage(void) {
|
|
|
308
366
|
}
|
|
309
367
|
- (void)playRow:(NSInteger)row throughFrame:(NSInteger)last oneShot:(BOOL)oneShot {
|
|
310
368
|
if (!oneShot && !self.oneShot && self.rowIndex == row) return;
|
|
369
|
+
self.lookDirection = -1;
|
|
311
370
|
self.rowIndex = row;
|
|
312
371
|
self.frames = [self framesFromZeroThrough:last];
|
|
313
372
|
self.sequenceIndex = 0;
|
|
@@ -365,6 +424,7 @@ static NSDictionary *LatestUsage(void) {
|
|
|
365
424
|
[self playRow:0 throughFrame:5 oneShot:NO];
|
|
366
425
|
}
|
|
367
426
|
- (void)nextFrame:(NSTimer *)timer {
|
|
427
|
+
if (self.lookDirection >= 0) return;
|
|
368
428
|
self.sequenceIndex += 1;
|
|
369
429
|
if (self.sequenceIndex >= self.frames.count) {
|
|
370
430
|
if (self.oneShot) {
|
|
@@ -469,12 +529,14 @@ static NSDictionary *LatestUsage(void) {
|
|
|
469
529
|
- (void)applySheet:(NSImage *)sheet petID:(NSString *)petID rowCount:(NSInteger)rowCount {
|
|
470
530
|
self.sheet = sheet;
|
|
471
531
|
self.spriteRowCount = rowCount;
|
|
532
|
+
self.lookDirection = -1;
|
|
472
533
|
self.currentPetID = petID;
|
|
473
534
|
self.rowIndex = 0;
|
|
474
535
|
self.frameIndex = 0;
|
|
475
536
|
self.sequenceIndex = 0;
|
|
476
537
|
self.frames = [self framesFromZeroThrough:5];
|
|
477
538
|
self.oneShot = NO;
|
|
539
|
+
[self updateLookTracking];
|
|
478
540
|
self.needsDisplay = YES;
|
|
479
541
|
}
|
|
480
542
|
- (void)selectPet:(NSMenuItem *)sender {
|