//
//  CacheTool.m
//  Unity-iPhone
//
//  Created by duowan123 on 2022/5/7.
//

#import "CacheTool.h"


@implementation CacheTool
#pragma mark ===============================================>>玩游戏过程中缓存 动作数据 和时间戳 数据存入plist
+(void)cacheGameInfoInfo:(GameInfo*)gameInfo{
 
        
    
//    //总数
//    int total_step_count = game->getMotionCount(STEP_COUNT) - gameInfo.step;
//    int total_jump_count = game->getMotionCount(JUMP_COUNT) - gameInfo.jump;
//    int total_crouch_count = game->getMotionCount(DOWN_COUNT) - gameInfo.crouch;
//    int total_tick_count = game->getMotionCount(KICK_COUNT) - gameInfo.tick;
//    int total_paper_count = game->getMotionCount(PAPER_COUNT) - gameInfo.paper;
//    int total_scissors_count = game->getMotionCount(SCISSORS_COUNT) - gameInfo.scissors;
//    int total_rock_count = game->getMotionCount(ROCK_COUNT) - gameInfo.rock;
//    int total_trample_count = game->getMotionCount(ROCK_COUNT) - gameInfo.trample;
//
//    //缓存pilst文件
//    NSMutableDictionary * motionCountObj = [NSMutableDictionary new];
//    [motionCountObj setObject:[NSNumber numberWithInt:total_step_count] forKey:@"step"];
//    [motionCountObj setObject:[NSNumber numberWithInt:total_jump_count] forKey:@"jump"];
//    [motionCountObj setObject:[NSNumber numberWithInt:total_crouch_count] forKey:@"crouch"];
//    [motionCountObj setObject:[NSNumber numberWithInt:total_tick_count] forKey:@"tick"];
//    [motionCountObj setObject:[NSNumber numberWithInt:total_paper_count] forKey:@"paper"];
//    [motionCountObj setObject:[NSNumber numberWithInt:total_scissors_count] forKey:@"scissors"];
//    [motionCountObj setObject:[NSNumber numberWithInt:total_rock_count] forKey:@"rock"];
//    [motionCountObj setObject:[NSNumber numberWithInt:0] forKey:@"trample"];
//
//    NSMutableDictionary * movements = [NSMutableDictionary new];
//    [movements setObject:motionCountObj forKey:@"movements"];
//    //游戏总共经历的时长（秒数）
//    NSTimeInterval durationTime = [[NSDate date] timeIntervalSinceDate:gameInfo.firstTime];
//    [movements setObject:[NSNumber numberWithInt:durationTime] forKey:@"duration"];
//
//    NSDictionary * dict = [NSDictionary dictionaryWithDictionary:movements];
//
//    //归档缓存
//    [IOS_NSUSERDEFAULT setObject:dict forKey:IOSSDK_MOTIONCOUNT];
//    [IOS_NSUSERDEFAULT synchronize];
//
}



//获取getUserInfo
+(NSString*)getUserInfo{
    NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSDictionary * user = jsonDict[@"user"];
    if ([user isKindOfClass:[NSNull class]] || user == nil || [user isEqual:[NSNull null]]){
        return @"";
    }else{
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
        NSString * userJsonString =  [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        return userJsonString;
    }
    
}

//获取token
+(NSString*)getToken{
    NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSString * token =  [urlDict objectForKey:@"token"];
    if ([token isKindOfClass:[NSNull class]] || token == nil || [token isEqual:[NSNull null]]){
//        [PopupView showCusHUDA:@"获取token失败,请从趣动启动"];
        return @"";
    }else{
        return token;
    }
    
}

//获取缓存game_id
+(NSString*)getGameId{
    NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSString * game_id =  [urlDict objectForKey:@"game_id"];
    if ([game_id isKindOfClass:[NSNull class]] || game_id == nil || [game_id isEqual:[NSNull null]]){
//         [PopupView showCusHUDA:@"获取id失败,请从趣动启动"];
        return @"";
    }else{
        return game_id;
    }
}

//获取缓存game_type
+(NSString*)getGameType{
    NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSString * game_type =  [urlDict objectForKey:@"game_type"];
    if ([game_type isKindOfClass:[NSNull class]] || game_type == nil || [game_type isEqual:[NSNull null]]){
//         [PopupView showCusHUDA:@"获取type失败,请从趣动启动"];
        return @"";
    }else{
        return game_type;
    }
}

//获取缓存mac
+(NSString*)getGameMac{
    NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSString * mac =  [urlDict objectForKey:@"mac"];
    if ([mac isKindOfClass:[NSNull class]] || mac == nil || [mac isEqual:[NSNull null]]){
//         [PopupView showCusHUDA:@"获取mac失败,请从趣动启动"];
        return @"";
    }else{
        return mac;
    }
}
    
//获取缓存邀请信息
+(NSString*)getInviteUser{
    NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSDictionary * invite = urlDict[@"invite"];
    if ([invite isKindOfClass:[NSNull class]] || invite == nil || [invite isEqual:[NSNull null]]){
//         [PopupView showCusHUDA:@"获取getInviteUser失败,请从趣动启动"];
        return @"";
    }else{
        //user字典 -> 字符串 -> Char
        NSDictionary * user =  [invite objectForKey:@"user"];
        NSData * userData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
        NSString * userString =  [[NSString alloc] initWithData:userData encoding:NSUTF8StringEncoding];
        return userString;
    }
        
}

+(NSString*)getInviteInfo{
    
    NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSDictionary * invite = urlDict[@"invite"];
    if ([invite isKindOfClass:[NSNull class]] || invite == nil || [invite isEqual:[NSNull null]]){
//         [PopupView showCusHUDA:@"获取邀请信息失败,请从趣动启动"];
        return @"";
    }else{
        NSString * info = [invite objectForKey:@"info"];
        return info;
    }
 
}

//获取缓存vibrate
+(NSString*)getGameVibrate{
    NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSString * vibrate =  [urlDict objectForKey:@"vibrate"];
    if ([vibrate isKindOfClass:[NSNull class]] || vibrate == nil || [vibrate isEqual:[NSNull null]]){
//         [PopupView showCusHUDA:@"获取mac失败,请从趣动启动"];
        return @"";
    }else{
        return vibrate;
    }
}

//获取缓存debug
+(NSString*)getGameDebug{
    NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
    NSString * debug =  [urlDict objectForKey:@"debug"];
    if ([debug isKindOfClass:[NSNull class]] || debug == nil || [debug isEqual:[NSNull null]]){
//         [PopupView showCusHUDA:@"获取mac失败,请从趣动启动"];
        return @"";
    }else{
        return debug;
    }
}

@end
