cc-pets 0.2.11 → 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 +4 -0
- package/CONTRIBUTING.md +3 -2
- package/README.md +7 -1
- package/Sources/CCPets/main.m +121 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/CONTRIBUTING.md
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
## 素材规范
|
|
14
14
|
|
|
15
15
|
- 支持 PNG 或 WebP,背景必须透明。
|
|
16
|
-
-
|
|
16
|
+
- 内置素材按 `8×9` 网格切分。外部 Codex/PetDex 素材支持
|
|
17
|
+
`spriteVersionNumber` v1(`1536×1872`、`8×9`)和
|
|
18
|
+
v2(`1536×2288`、`8×11`),每格均为 `192×208`。
|
|
17
19
|
- 九行动画帧数依次为 `6/8/8/4/5/8/6/6/6`,未使用单元格必须保持透明。
|
|
18
20
|
- 请在 Pull Request 中说明素材作者、来源和许可证。
|
|
19
|
-
|
package/README.md
CHANGED
|
@@ -61,6 +61,10 @@ Claude Code Hook 会合并到 `~/.claude/settings.json`,现有的 `env`、`mod
|
|
|
61
61
|
|
|
62
62
|
当 `~/.petdex/pets/<name>/` 只有 `pet.json` 时,程序会自动到
|
|
63
63
|
`~/.codex/pets/<name>/` 查找同名桌宠的 `spritesheet.webp` 或 `spritesheet.png`。
|
|
64
|
+
外部素材遵循 Codex 桌面端的 `spriteVersionNumber` 协议:字段缺失或为 `1` 时按
|
|
65
|
+
`1536×1872`、`8×9` 网格解析;为 `2` 时按 `1536×2288`、`8×11` 网格解析。
|
|
66
|
+
v2 新增的最后两行用于十六向鼠标跟随;只在桌宠空闲时启用,拖动、悬停互动和
|
|
67
|
+
Agent 状态动画会优先播放。
|
|
64
68
|
|
|
65
69
|
交互区域存在重叠时,按“口袋、头部、脚部、身体左右侧”的优先级识别。拖动超过
|
|
66
70
|
3 像素后才进入拖动状态,避免普通点击被误判为拖动。
|
|
@@ -227,7 +231,9 @@ Claude.ai Pro/Max 订阅账号,并在会话完成首次 API 响应后出现;
|
|
|
227
231
|
## 素材与版权
|
|
228
232
|
|
|
229
233
|
桌宠素材统一放在 `Sources/CCPets/Resources/`,程序会自动收集其中的 `.webp` 和 `.png` 文件。
|
|
230
|
-
|
|
234
|
+
内置素材按 `8×9` 网格解析。外部 Codex/PetDex 素材支持
|
|
235
|
+
`spriteVersionNumber` v1(`1536×1872`、`8×9`)和
|
|
236
|
+
v2(`1536×2288`、`8×11`),单元格均为 `192×208`,前九行遵循相同的动作协议。
|
|
231
237
|
角色可能属于受版权保护的作品;公开
|
|
232
238
|
发布本项目或 npm 包前,请确认已经获得素材的使用和分发授权,或替换为原创、可公开分发的素材。
|
|
233
239
|
|
package/Sources/CCPets/main.m
CHANGED
|
@@ -267,6 +267,8 @@ static NSDictionary *LatestUsage(void) {
|
|
|
267
267
|
|
|
268
268
|
@interface PetView : NSView
|
|
269
269
|
@property NSImage *sheet;
|
|
270
|
+
@property NSInteger spriteRowCount;
|
|
271
|
+
@property NSInteger lookDirection;
|
|
270
272
|
@property NSInteger frameIndex;
|
|
271
273
|
@property NSInteger rowIndex;
|
|
272
274
|
@property NSArray<NSNumber *> *frames;
|
|
@@ -277,6 +279,8 @@ static NSDictionary *LatestUsage(void) {
|
|
|
277
279
|
@property NSPoint dragStartMouse;
|
|
278
280
|
@property NSPoint dragStartWindowOrigin;
|
|
279
281
|
@property NSString *currentPetID;
|
|
282
|
+
@property id globalMouseMonitor;
|
|
283
|
+
@property id localMouseMonitor;
|
|
280
284
|
@property(copy) void (^pocketHoverChanged)(BOOL hovering);
|
|
281
285
|
@property(copy) void (^positionChanged)(void);
|
|
282
286
|
@property(copy) void (^dragStateChanged)(BOOL dragging);
|
|
@@ -285,9 +289,11 @@ static NSDictionary *LatestUsage(void) {
|
|
|
285
289
|
@end
|
|
286
290
|
|
|
287
291
|
@implementation PetView
|
|
288
|
-
- (instancetype)initWithFrame:(NSRect)frame sheet:(NSImage *)sheet {
|
|
292
|
+
- (instancetype)initWithFrame:(NSRect)frame sheet:(NSImage *)sheet rowCount:(NSInteger)rowCount {
|
|
289
293
|
if ((self = [super initWithFrame:frame])) {
|
|
290
294
|
_sheet = sheet;
|
|
295
|
+
_spriteRowCount = rowCount;
|
|
296
|
+
_lookDirection = -1;
|
|
291
297
|
_frames = @[@0, @1, @2, @3, @4, @5];
|
|
292
298
|
[NSTimer scheduledTimerWithTimeInterval:0.22 target:self
|
|
293
299
|
selector:@selector(nextFrame:) userInfo:nil repeats:YES];
|
|
@@ -296,9 +302,63 @@ static NSDictionary *LatestUsage(void) {
|
|
|
296
302
|
NSTrackingActiveAlways | NSTrackingInVisibleRect
|
|
297
303
|
owner:self userInfo:nil];
|
|
298
304
|
[self addTrackingArea:tracking];
|
|
305
|
+
[self updateLookTracking];
|
|
299
306
|
}
|
|
300
307
|
return self;
|
|
301
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
|
+
}
|
|
302
362
|
- (NSArray<NSNumber *> *)framesFromZeroThrough:(NSInteger)last {
|
|
303
363
|
NSMutableArray<NSNumber *> *result = [NSMutableArray arrayWithCapacity:last + 1];
|
|
304
364
|
for (NSInteger index = 0; index <= last; index++) [result addObject:@(index)];
|
|
@@ -306,6 +366,7 @@ static NSDictionary *LatestUsage(void) {
|
|
|
306
366
|
}
|
|
307
367
|
- (void)playRow:(NSInteger)row throughFrame:(NSInteger)last oneShot:(BOOL)oneShot {
|
|
308
368
|
if (!oneShot && !self.oneShot && self.rowIndex == row) return;
|
|
369
|
+
self.lookDirection = -1;
|
|
309
370
|
self.rowIndex = row;
|
|
310
371
|
self.frames = [self framesFromZeroThrough:last];
|
|
311
372
|
self.sequenceIndex = 0;
|
|
@@ -363,6 +424,7 @@ static NSDictionary *LatestUsage(void) {
|
|
|
363
424
|
[self playRow:0 throughFrame:5 oneShot:NO];
|
|
364
425
|
}
|
|
365
426
|
- (void)nextFrame:(NSTimer *)timer {
|
|
427
|
+
if (self.lookDirection >= 0) return;
|
|
366
428
|
self.sequenceIndex += 1;
|
|
367
429
|
if (self.sequenceIndex >= self.frames.count) {
|
|
368
430
|
if (self.oneShot) {
|
|
@@ -457,21 +519,24 @@ static NSDictionary *LatestUsage(void) {
|
|
|
457
519
|
}
|
|
458
520
|
- (void)drawRect:(NSRect)dirtyRect {
|
|
459
521
|
CGFloat cellWidth = self.sheet.size.width / 8.0;
|
|
460
|
-
CGFloat cellHeight = self.sheet.size.height /
|
|
522
|
+
CGFloat cellHeight = self.sheet.size.height / self.spriteRowCount;
|
|
461
523
|
NSRect source = NSMakeRect(self.frameIndex * cellWidth,
|
|
462
524
|
self.sheet.size.height - (self.rowIndex + 1) * cellHeight, cellWidth, cellHeight);
|
|
463
525
|
[self.sheet drawInRect:NSInsetRect(self.bounds, 2, 0) fromRect:source
|
|
464
526
|
operation:NSCompositingOperationSourceOver fraction:1.0
|
|
465
527
|
respectFlipped:NO hints:@{NSImageHintInterpolation: @(NSImageInterpolationNone)}];
|
|
466
528
|
}
|
|
467
|
-
- (void)applySheet:(NSImage *)sheet petID:(NSString *)petID {
|
|
529
|
+
- (void)applySheet:(NSImage *)sheet petID:(NSString *)petID rowCount:(NSInteger)rowCount {
|
|
468
530
|
self.sheet = sheet;
|
|
531
|
+
self.spriteRowCount = rowCount;
|
|
532
|
+
self.lookDirection = -1;
|
|
469
533
|
self.currentPetID = petID;
|
|
470
534
|
self.rowIndex = 0;
|
|
471
535
|
self.frameIndex = 0;
|
|
472
536
|
self.sequenceIndex = 0;
|
|
473
537
|
self.frames = [self framesFromZeroThrough:5];
|
|
474
538
|
self.oneShot = NO;
|
|
539
|
+
[self updateLookTracking];
|
|
475
540
|
self.needsDisplay = YES;
|
|
476
541
|
}
|
|
477
542
|
- (void)selectPet:(NSMenuItem *)sender {
|
|
@@ -860,15 +925,32 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
860
925
|
@end
|
|
861
926
|
|
|
862
927
|
@implementation AppDelegate
|
|
863
|
-
- (
|
|
864
|
-
NSString *configuredName = nil;
|
|
928
|
+
- (NSDictionary *)petManifestInDirectory:(NSString *)directory {
|
|
865
929
|
NSString *jsonPath = [directory stringByAppendingPathComponent:@"pet.json"];
|
|
866
930
|
NSData *jsonData = [NSData dataWithContentsOfFile:jsonPath];
|
|
867
|
-
if (jsonData) {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
931
|
+
if (!jsonData) return @{};
|
|
932
|
+
id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
|
933
|
+
return [json isKindOfClass:NSDictionary.class] ? json : @{};
|
|
934
|
+
}
|
|
935
|
+
- (NSInteger)spriteVersionInDirectory:(NSString *)directory fallbackDirectory:(NSString *)fallbackDirectory {
|
|
936
|
+
NSArray<NSString *> *directories = fallbackDirectory.length > 0
|
|
937
|
+
? @[directory, fallbackDirectory]
|
|
938
|
+
: @[directory];
|
|
939
|
+
for (NSString *candidate in directories) {
|
|
940
|
+
id value = [self petManifestInDirectory:candidate][@"spriteVersionNumber"];
|
|
941
|
+
if (![value isKindOfClass:NSNumber.class]) continue;
|
|
942
|
+
NSInteger version = [value integerValue];
|
|
943
|
+
if (version == 1 || version == 2) return version;
|
|
871
944
|
}
|
|
945
|
+
return 1;
|
|
946
|
+
}
|
|
947
|
+
- (NSInteger)spriteRowCountForVersion:(NSInteger)version {
|
|
948
|
+
return version == 2 ? 11 : 9;
|
|
949
|
+
}
|
|
950
|
+
- (NSString *)spritePathInDirectory:(NSString *)directory {
|
|
951
|
+
NSString *configuredName = nil;
|
|
952
|
+
id value = [self petManifestInDirectory:directory][@"spritesheetPath"];
|
|
953
|
+
if ([value isKindOfClass:NSString.class]) configuredName = [value lastPathComponent];
|
|
872
954
|
NSMutableArray<NSString *> *names = [NSMutableArray array];
|
|
873
955
|
if (configuredName.length > 0) [names addObject:configuredName];
|
|
874
956
|
[names addObjectsFromArray:@[@"spritesheet.webp", @"spritesheet.png"]];
|
|
@@ -900,17 +982,34 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
900
982
|
NSMutableSet<NSString *> *externalNames = [NSMutableSet set];
|
|
901
983
|
|
|
902
984
|
for (NSString *name in [self petDirectoryNamesAtPath:petdexRoot]) {
|
|
903
|
-
NSString *
|
|
904
|
-
|
|
985
|
+
NSString *petdexDirectory = [petdexRoot stringByAppendingPathComponent:name];
|
|
986
|
+
NSString *codexDirectory = [codexRoot stringByAppendingPathComponent:name];
|
|
987
|
+
NSString *path = [self spritePathInDirectory:petdexDirectory];
|
|
988
|
+
if (!path) path = [self spritePathInDirectory:codexDirectory];
|
|
905
989
|
if (!path) continue;
|
|
906
|
-
|
|
990
|
+
NSInteger version = [self spriteVersionInDirectory:petdexDirectory fallbackDirectory:codexDirectory];
|
|
991
|
+
[result addObject:@{
|
|
992
|
+
@"id": [@"external:" stringByAppendingString:name],
|
|
993
|
+
@"name": name,
|
|
994
|
+
@"path": path,
|
|
995
|
+
@"spriteVersionNumber": @(version),
|
|
996
|
+
@"spriteRowCount": @([self spriteRowCountForVersion:version])
|
|
997
|
+
}];
|
|
907
998
|
[externalNames addObject:name];
|
|
908
999
|
}
|
|
909
1000
|
for (NSString *name in [self petDirectoryNamesAtPath:codexRoot]) {
|
|
910
1001
|
if ([externalNames containsObject:name]) continue;
|
|
911
|
-
NSString *
|
|
1002
|
+
NSString *codexDirectory = [codexRoot stringByAppendingPathComponent:name];
|
|
1003
|
+
NSString *path = [self spritePathInDirectory:codexDirectory];
|
|
912
1004
|
if (!path) continue;
|
|
913
|
-
|
|
1005
|
+
NSInteger version = [self spriteVersionInDirectory:codexDirectory fallbackDirectory:nil];
|
|
1006
|
+
[result addObject:@{
|
|
1007
|
+
@"id": [@"external:" stringByAppendingString:name],
|
|
1008
|
+
@"name": name,
|
|
1009
|
+
@"path": path,
|
|
1010
|
+
@"spriteVersionNumber": @(version),
|
|
1011
|
+
@"spriteRowCount": @([self spriteRowCountForVersion:version])
|
|
1012
|
+
}];
|
|
914
1013
|
[externalNames addObject:name];
|
|
915
1014
|
}
|
|
916
1015
|
|
|
@@ -921,7 +1020,9 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
921
1020
|
[result addObject:@{
|
|
922
1021
|
@"id": [@"builtin:" stringByAppendingString:fileName],
|
|
923
1022
|
@"name": fileName.stringByDeletingPathExtension,
|
|
924
|
-
@"path": [self.binaryDirectory stringByAppendingPathComponent:fileName]
|
|
1023
|
+
@"path": [self.binaryDirectory stringByAppendingPathComponent:fileName],
|
|
1024
|
+
@"spriteVersionNumber": @1,
|
|
1025
|
+
@"spriteRowCount": @9
|
|
925
1026
|
}];
|
|
926
1027
|
}
|
|
927
1028
|
return result;
|
|
@@ -1003,7 +1104,9 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
1003
1104
|
|
|
1004
1105
|
NSView *root = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, size.width, size.height)];
|
|
1005
1106
|
self.panel.contentView = root;
|
|
1006
|
-
|
|
1107
|
+
NSInteger spriteRowCount = [selectedOption[@"spriteRowCount"] integerValue] ?: 9;
|
|
1108
|
+
self.petView = [[PetView alloc] initWithFrame:NSMakeRect(43, 0, 144, 150)
|
|
1109
|
+
sheet:image rowCount:spriteRowCount];
|
|
1007
1110
|
self.petView.currentPetID = selected;
|
|
1008
1111
|
__weak typeof(self) weakSelf = self;
|
|
1009
1112
|
self.petView.pocketHoverChanged = ^(BOOL hovering) {
|
|
@@ -1110,7 +1213,8 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
1110
1213
|
if (!option) return;
|
|
1111
1214
|
NSImage *image = [[NSImage alloc] initWithContentsOfFile:option[@"path"]];
|
|
1112
1215
|
if (!image) return;
|
|
1113
|
-
[
|
|
1216
|
+
NSInteger spriteRowCount = [option[@"spriteRowCount"] integerValue] ?: 9;
|
|
1217
|
+
[self.petView applySheet:image petID:petID rowCount:spriteRowCount];
|
|
1114
1218
|
[NSUserDefaults.standardUserDefaults setObject:petID forKey:@"CCPetsSelectedSprite"];
|
|
1115
1219
|
}
|
|
1116
1220
|
- (void)prepareAgentEventReader {
|