cc-pets 0.2.10 → 0.2.12

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 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  本项目遵循语义化版本号。
4
4
 
5
+ ## [未发布]
6
+
7
+ - 支持 Codex/PetDex `spriteVersionNumber: 2` 的 `8×11` 精灵图布局。
8
+
5
9
  ## [0.2.0] - 2026-07-22
6
10
 
7
11
  - 项目和 npm 包更名为 CC Pets。
package/CONTRIBUTING.md CHANGED
@@ -13,7 +13,8 @@
13
13
  ## 素材规范
14
14
 
15
15
  - 支持 PNG 或 WebP,背景必须透明。
16
- - 画布为 `1536×1872`,按 `8×9` 网格切分,每格 `192×208`。
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,9 @@ 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 新增的最后两行朝向帧当前不会播放。
64
67
 
65
68
  交互区域存在重叠时,按“口袋、头部、脚部、身体左右侧”的优先级识别。拖动超过
66
69
  3 像素后才进入拖动状态,避免普通点击被误判为拖动。
@@ -227,7 +230,9 @@ Claude.ai Pro/Max 订阅账号,并在会话完成首次 API 响应后出现;
227
230
  ## 素材与版权
228
231
 
229
232
  桌宠素材统一放在 `Sources/CCPets/Resources/`,程序会自动收集其中的 `.webp` 和 `.png` 文件。
230
- 素材需要使用 `1536×1872` 画布,按 `8×9` 网格切分为 `192×208` 单元格,并遵循相同的帧数和动作行协议。
233
+ 内置素材按 `8×9` 网格解析。外部 Codex/PetDex 素材支持
234
+ `spriteVersionNumber` v1(`1536×1872`、`8×9`)和
235
+ v2(`1536×2288`、`8×11`),单元格均为 `192×208`,前九行遵循相同的动作协议。
231
236
  角色可能属于受版权保护的作品;公开
232
237
  发布本项目或 npm 包前,请确认已经获得素材的使用和分发授权,或替换为原创、可公开分发的素材。
233
238
 
@@ -267,6 +267,7 @@ static NSDictionary *LatestUsage(void) {
267
267
 
268
268
  @interface PetView : NSView
269
269
  @property NSImage *sheet;
270
+ @property NSInteger spriteRowCount;
270
271
  @property NSInteger frameIndex;
271
272
  @property NSInteger rowIndex;
272
273
  @property NSArray<NSNumber *> *frames;
@@ -285,9 +286,10 @@ static NSDictionary *LatestUsage(void) {
285
286
  @end
286
287
 
287
288
  @implementation PetView
288
- - (instancetype)initWithFrame:(NSRect)frame sheet:(NSImage *)sheet {
289
+ - (instancetype)initWithFrame:(NSRect)frame sheet:(NSImage *)sheet rowCount:(NSInteger)rowCount {
289
290
  if ((self = [super initWithFrame:frame])) {
290
291
  _sheet = sheet;
292
+ _spriteRowCount = rowCount;
291
293
  _frames = @[@0, @1, @2, @3, @4, @5];
292
294
  [NSTimer scheduledTimerWithTimeInterval:0.22 target:self
293
295
  selector:@selector(nextFrame:) userInfo:nil repeats:YES];
@@ -457,15 +459,16 @@ static NSDictionary *LatestUsage(void) {
457
459
  }
458
460
  - (void)drawRect:(NSRect)dirtyRect {
459
461
  CGFloat cellWidth = self.sheet.size.width / 8.0;
460
- CGFloat cellHeight = self.sheet.size.height / 9.0;
462
+ CGFloat cellHeight = self.sheet.size.height / self.spriteRowCount;
461
463
  NSRect source = NSMakeRect(self.frameIndex * cellWidth,
462
464
  self.sheet.size.height - (self.rowIndex + 1) * cellHeight, cellWidth, cellHeight);
463
465
  [self.sheet drawInRect:NSInsetRect(self.bounds, 2, 0) fromRect:source
464
466
  operation:NSCompositingOperationSourceOver fraction:1.0
465
467
  respectFlipped:NO hints:@{NSImageHintInterpolation: @(NSImageInterpolationNone)}];
466
468
  }
467
- - (void)applySheet:(NSImage *)sheet petID:(NSString *)petID {
469
+ - (void)applySheet:(NSImage *)sheet petID:(NSString *)petID rowCount:(NSInteger)rowCount {
468
470
  self.sheet = sheet;
471
+ self.spriteRowCount = rowCount;
469
472
  self.currentPetID = petID;
470
473
  self.rowIndex = 0;
471
474
  self.frameIndex = 0;
@@ -860,15 +863,32 @@ static int RenderQuotaDashboard(NSString *path) {
860
863
  @end
861
864
 
862
865
  @implementation AppDelegate
863
- - (NSString *)spritePathInDirectory:(NSString *)directory {
864
- NSString *configuredName = nil;
866
+ - (NSDictionary *)petManifestInDirectory:(NSString *)directory {
865
867
  NSString *jsonPath = [directory stringByAppendingPathComponent:@"pet.json"];
866
868
  NSData *jsonData = [NSData dataWithContentsOfFile:jsonPath];
867
- if (jsonData) {
868
- NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
869
- id value = json[@"spritesheetPath"];
870
- if ([value isKindOfClass:NSString.class]) configuredName = [value lastPathComponent];
869
+ if (!jsonData) return @{};
870
+ id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
871
+ return [json isKindOfClass:NSDictionary.class] ? json : @{};
872
+ }
873
+ - (NSInteger)spriteVersionInDirectory:(NSString *)directory fallbackDirectory:(NSString *)fallbackDirectory {
874
+ NSArray<NSString *> *directories = fallbackDirectory.length > 0
875
+ ? @[directory, fallbackDirectory]
876
+ : @[directory];
877
+ for (NSString *candidate in directories) {
878
+ id value = [self petManifestInDirectory:candidate][@"spriteVersionNumber"];
879
+ if (![value isKindOfClass:NSNumber.class]) continue;
880
+ NSInteger version = [value integerValue];
881
+ if (version == 1 || version == 2) return version;
871
882
  }
883
+ return 1;
884
+ }
885
+ - (NSInteger)spriteRowCountForVersion:(NSInteger)version {
886
+ return version == 2 ? 11 : 9;
887
+ }
888
+ - (NSString *)spritePathInDirectory:(NSString *)directory {
889
+ NSString *configuredName = nil;
890
+ id value = [self petManifestInDirectory:directory][@"spritesheetPath"];
891
+ if ([value isKindOfClass:NSString.class]) configuredName = [value lastPathComponent];
872
892
  NSMutableArray<NSString *> *names = [NSMutableArray array];
873
893
  if (configuredName.length > 0) [names addObject:configuredName];
874
894
  [names addObjectsFromArray:@[@"spritesheet.webp", @"spritesheet.png"]];
@@ -900,17 +920,34 @@ static int RenderQuotaDashboard(NSString *path) {
900
920
  NSMutableSet<NSString *> *externalNames = [NSMutableSet set];
901
921
 
902
922
  for (NSString *name in [self petDirectoryNamesAtPath:petdexRoot]) {
903
- NSString *path = [self spritePathInDirectory:[petdexRoot stringByAppendingPathComponent:name]];
904
- if (!path) path = [self spritePathInDirectory:[codexRoot stringByAppendingPathComponent:name]];
923
+ NSString *petdexDirectory = [petdexRoot stringByAppendingPathComponent:name];
924
+ NSString *codexDirectory = [codexRoot stringByAppendingPathComponent:name];
925
+ NSString *path = [self spritePathInDirectory:petdexDirectory];
926
+ if (!path) path = [self spritePathInDirectory:codexDirectory];
905
927
  if (!path) continue;
906
- [result addObject:@{@"id": [@"external:" stringByAppendingString:name], @"name": name, @"path": path}];
928
+ NSInteger version = [self spriteVersionInDirectory:petdexDirectory fallbackDirectory:codexDirectory];
929
+ [result addObject:@{
930
+ @"id": [@"external:" stringByAppendingString:name],
931
+ @"name": name,
932
+ @"path": path,
933
+ @"spriteVersionNumber": @(version),
934
+ @"spriteRowCount": @([self spriteRowCountForVersion:version])
935
+ }];
907
936
  [externalNames addObject:name];
908
937
  }
909
938
  for (NSString *name in [self petDirectoryNamesAtPath:codexRoot]) {
910
939
  if ([externalNames containsObject:name]) continue;
911
- NSString *path = [self spritePathInDirectory:[codexRoot stringByAppendingPathComponent:name]];
940
+ NSString *codexDirectory = [codexRoot stringByAppendingPathComponent:name];
941
+ NSString *path = [self spritePathInDirectory:codexDirectory];
912
942
  if (!path) continue;
913
- [result addObject:@{@"id": [@"external:" stringByAppendingString:name], @"name": name, @"path": path}];
943
+ NSInteger version = [self spriteVersionInDirectory:codexDirectory fallbackDirectory:nil];
944
+ [result addObject:@{
945
+ @"id": [@"external:" stringByAppendingString:name],
946
+ @"name": name,
947
+ @"path": path,
948
+ @"spriteVersionNumber": @(version),
949
+ @"spriteRowCount": @([self spriteRowCountForVersion:version])
950
+ }];
914
951
  [externalNames addObject:name];
915
952
  }
916
953
 
@@ -921,7 +958,9 @@ static int RenderQuotaDashboard(NSString *path) {
921
958
  [result addObject:@{
922
959
  @"id": [@"builtin:" stringByAppendingString:fileName],
923
960
  @"name": fileName.stringByDeletingPathExtension,
924
- @"path": [self.binaryDirectory stringByAppendingPathComponent:fileName]
961
+ @"path": [self.binaryDirectory stringByAppendingPathComponent:fileName],
962
+ @"spriteVersionNumber": @1,
963
+ @"spriteRowCount": @9
925
964
  }];
926
965
  }
927
966
  return result;
@@ -1003,7 +1042,9 @@ static int RenderQuotaDashboard(NSString *path) {
1003
1042
 
1004
1043
  NSView *root = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, size.width, size.height)];
1005
1044
  self.panel.contentView = root;
1006
- self.petView = [[PetView alloc] initWithFrame:NSMakeRect(43, 0, 144, 150) sheet:image];
1045
+ NSInteger spriteRowCount = [selectedOption[@"spriteRowCount"] integerValue] ?: 9;
1046
+ self.petView = [[PetView alloc] initWithFrame:NSMakeRect(43, 0, 144, 150)
1047
+ sheet:image rowCount:spriteRowCount];
1007
1048
  self.petView.currentPetID = selected;
1008
1049
  __weak typeof(self) weakSelf = self;
1009
1050
  self.petView.pocketHoverChanged = ^(BOOL hovering) {
@@ -1110,7 +1151,8 @@ static int RenderQuotaDashboard(NSString *path) {
1110
1151
  if (!option) return;
1111
1152
  NSImage *image = [[NSImage alloc] initWithContentsOfFile:option[@"path"]];
1112
1153
  if (!image) return;
1113
- [self.petView applySheet:image petID:petID];
1154
+ NSInteger spriteRowCount = [option[@"spriteRowCount"] integerValue] ?: 9;
1155
+ [self.petView applySheet:image petID:petID rowCount:spriteRowCount];
1114
1156
  [NSUserDefaults.standardUserDefaults setObject:petID forKey:@"CCPetsSelectedSprite"];
1115
1157
  }
1116
1158
  - (void)prepareAgentEventReader {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-pets",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "A native macOS desktop pet for Codex CLI and Claude Code",
5
5
  "author": "wangxinyusqn",
6
6
  "license": "MIT",