加载字符串到 NSMutableDictionary 示例

本文介绍了一个游戏开发中的关卡时间和动画顶点数据的加载实现方式。通过读取配置文件来设置不同关卡的时长,并使用特定格式的文本文件来存储动画顶点信息。

// 加载每个关卡钟表走动的时间~

-(void) loadLevelDurationTime {

_levelDurationTimeData = [[NSMutableArray alloc] init];

int levelTotalCount = [_gCfg ifk:@"levelTotalCount"];

for(int i = 0; i < levelTotalCount; i ++) {

[_levelDurationTimeData addObject:@"10"]; // 每关默认10秒钟,如果配置文件中有做配置,则将默认覆盖掉~

}

NSString *absPath = [[NSBundle mainBundle] pathForResource:@"levelDuration" ofType:@"txt"];

NSFileManager *fm = [NSFileManager defaultManager];

if([fm fileExistsAtPath:absPath] == NO) {

NSLog(@"File not exists!");

return;

}

NSString *fileContent = [NSString stringWithContentsOfFile:absPath

encoding:NSUTF8StringEncoding

error:nil];

// NSLog(@"file contents:\n%@", fileContent);

NSArray *cfgTime = [fileContent componentsSeparatedByString:@"\n"];

int lessLength = MIN( [cfgTime count], [_levelDurationTimeData count] );

for(int i = 0; i < lessLength; i ++) {

[_levelDurationTimeData replaceObjectAtIndex:i withObject:[cfgTime objectAtIndex:i]];

// NSLog(@"%d关的等待时间长度为: %@", i, [_levelDurationTimeData objectAtIndex:i]);

}

}


// 加载sprite动画的顶点信息~

-(void) loadAnimationData {

_animVerticesDic = [[NSMutableDictionary alloc] initWithCapacity:20];

NSString *absPath = [[NSBundle mainBundle] pathForResource:@"animVerticesSummary" ofType:@"txt"];

NSFileManager *fm = [NSFileManager defaultManager];

if([fm fileExistsAtPath:absPath] == NO) {

NSLog(@"File not exists!");

return;

}

NSString *fileContent = [NSString stringWithContentsOfFile:absPathencoding:NSUTF8StringEncodingerror:nil];

NSArray *verticesSummaryArray = [fileContent componentsSeparatedByString:@"\n"];

int len = [verticesSummaryArray count];

for(int i = 0; i < len; i ++) {

NSString *unit = [verticesSummaryArray objectAtIndex:i];

NSRange range = [unit rangeOfString:@"="];

// NSLog(@"range.location=%d, range.length=%d", range.location, range.length);

NSString *keyStr = [unit substringToIndex:range.location];

// NSLog(@"keyString: %@", keyStr);

NSString *valueStr = [unit substringFromIndex:range.location+1];

// NSLog(@"valueString: %@", valueStr);

[_animVerticesDic setObject:valueStr forKey:keyStr];

}

}

Building wheel for quickjs (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [12 lines of output] running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-313\quickjs copying quickjs\__init__.py -> build\lib.win-amd64-cpython-313\quickjs running build_ext building '_quickjs' extension creating build\temp.win-amd64-cpython-313\Release creating build\temp.win-amd64-cpython-313\Release\upstream-quickjs "D:\Visual Studio\Visual Studio 2022\Community\VC\Tools\MSVC\14.43.34808\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DCONFIG_VERSION=\"2021-03-27\" -DCONFIG_BIGNUM -IE:\Python3\include -IE:\Python3\Include "-ID:\Visual Studio\Visual Studio 2022\Community\VC\Tools\MSVC\14.43.34808\include" "-ID:\Visual Studio\Visual Studio 2022\Community\VC\Tools\MSVC\14.43.34808\ATLMFC\include" "-ID:\Visual Studio\Visual Studio 2022\Community\VC\Auxiliary\VS\include" "-ID:\Windows Kits\10\include\10.0.22621.0\ucrt" "-ID:\Windows Kits\10\\include\10.0.22621.0\\um" "-ID:\Windows Kits\10\\include\10.0.22621.0\\shared" "-ID:\Windows Kits\10\\include\10.0.22621.0\\winrt" "-ID:\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" /Tcmodule.c /Fobuild\temp.win-amd64-cpython-313\Release\module.obj -Werror=incompatible-pointer-types cl: 命令行 error D8021 :无效的数值参数“/Werror=incompatible-pointer-types” error: command 'D:\\Visual Studio\\Visual Studio 2022\\Community\\VC\\Tools\\MSVC\\14.43.34808\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for quickjs Running setup.py clean for quickjs Failed to build quickjs ERROR: Failed to build installable wheels for some pyproject.toml based projects (quickjs)
03-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值