project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
changeset 6266 b02a1e92dba2
parent 6265 a6944f94c19f
child 6276 1e2f8da1860a
equal deleted inserted replaced
6265:a6944f94c19f 6266:b02a1e92dba2
    26 #import "AudioManagerController.h"
    26 #import "AudioManagerController.h"
    27 #import "ObjcExports.h"
    27 #import "ObjcExports.h"
    28 
    28 
    29 @implementation GameInterfaceBridge
    29 @implementation GameInterfaceBridge
    30 
    30 
    31 -(id) initWithController:(id) viewController {
       
    32     if (self = [super init]) {
       
    33     }
       
    34     return self;
       
    35 }
       
    36 
       
    37 -(void) dealloc {
       
    38     [super dealloc];
       
    39 }
       
    40 
       
    41 #pragma mark -
       
    42 // main routine for calling the actual game engine
    31 // main routine for calling the actual game engine
    43 -(void) engineLaunchOn:(NSInteger) ipcPort withArgument:(NSString *)path {
    32 +(void) engineLaunchOn:(NSInteger) ipcPort withArgument:(NSString *)path {
    44     const char *gameArgs[11];
    33     const char *gameArgs[11];
    45     CGFloat width, height;
    34     CGFloat width, height;
    46     CGFloat screenScale = [[UIScreen mainScreen] safeScale];
    35     CGFloat screenScale = [[UIScreen mainScreen] safeScale];
    47     NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",ipcPort];
    36     NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",ipcPort];
    48     NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
    37     NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
   105     // this is the pascal function that starts the game
    94     // this is the pascal function that starts the game
   106     Game(gameArgs);
    95     Game(gameArgs);
   107 }
    96 }
   108 
    97 
   109 // prepares the controllers for hosting a game
    98 // prepares the controllers for hosting a game
   110 -(void) prepareEngineOn:(NSString *)pathOrNil withOptions:(NSDictionary *)optionsOrNil {
    99 +(void) prepareEngineOn:(NSString *)pathOrNil withOptions:(NSDictionary *)optionsOrNil {
   111     EngineProtocolNetwork *proto = [[EngineProtocolNetwork alloc] init];
   100     EngineProtocolNetwork *proto = [[EngineProtocolNetwork alloc] init];
   112     NSInteger ipcPort = [proto spawnThread:pathOrNil withOptions:optionsOrNil];
   101     NSInteger ipcPort = [proto spawnThread:pathOrNil withOptions:optionsOrNil];
   113 
   102 
   114     CGRect theFrame = [[UIScreen mainScreen] bounds];
   103     CGRect theFrame = [[UIScreen mainScreen] bounds];
   115     UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow];
   104     UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow];
   158 
   147 
   159     [AudioManagerController playBackgroundMusic];
   148     [AudioManagerController playBackgroundMusic];
   160 }
   149 }
   161 
   150 
   162 // set up variables for a local game
   151 // set up variables for a local game
   163 -(void) startLocalGame:(NSDictionary *)withOptions {
   152 +(void) startLocalGame:(NSDictionary *)withOptions {
   164     [HWUtils setGameType:gtLocal];
   153     [HWUtils setGameType:gtLocal];
   165 
   154 
   166     NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
   155     NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
   167     [outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"];
   156     [outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"];
   168     NSString *savePath = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]];
   157     NSString *savePath = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]];
   170 
   159 
   171     // in the rare case in which a savefile with the same name exists the older one must be removed (or it gets corrupted)
   160     // in the rare case in which a savefile with the same name exists the older one must be removed (or it gets corrupted)
   172     if ([[NSFileManager defaultManager] fileExistsAtPath:savePath])
   161     if ([[NSFileManager defaultManager] fileExistsAtPath:savePath])
   173         [[NSFileManager defaultManager] removeItemAtPath:savePath error:nil];
   162         [[NSFileManager defaultManager] removeItemAtPath:savePath error:nil];
   174 
   163 
   175     [self prepareEngineOn:savePath withOptions:withOptions];
   164     [GameInterfaceBridge prepareEngineOn:savePath withOptions:withOptions];
   176     [savePath release];
   165     [savePath release];
   177 }
   166 }
   178 
   167 
   179 // set up variables for a save game
   168 // set up variables for a save game
   180 -(void) startSaveGame:(NSString *)atPath {
   169 +(void) startSaveGame:(NSString *)atPath {
   181     [HWUtils setGameType:gtSave];
   170     [HWUtils setGameType:gtSave];
   182     [self prepareEngineOn:atPath withOptions:nil];
   171     [GameInterfaceBridge prepareEngineOn:atPath withOptions:nil];
   183 }
   172 }
   184 
   173 
   185 -(void) startMissionGame:(NSString *)withScript {
   174 +(void) startMissionGame:(NSString *)withScript {
   186     [HWUtils setGameType:gtMission];
   175     [HWUtils setGameType:gtMission];
   187 
   176 
   188     NSString *missionPath = [[NSString alloc] initWithFormat:@"escript Missions/Training/%@.lua",withScript];
   177     NSString *missionPath = [[NSString alloc] initWithFormat:@"escript Missions/Training/%@.lua",withScript];
   189     NSDictionary *missionLine = [[NSDictionary alloc] initWithObjectsAndKeys:missionPath,@"mission_command",nil];
   178     NSDictionary *missionLine = [[NSDictionary alloc] initWithObjectsAndKeys:missionPath,@"mission_command",nil];
   190     [missionPath release];
   179     [missionPath release];
   191 
   180 
   192     [self prepareEngineOn:nil withOptions:missionLine];
   181     [GameInterfaceBridge prepareEngineOn:nil withOptions:missionLine];
   193     [missionLine release];
   182     [missionLine release];
   194 }
   183 }
   195 
   184 
   196 /*
   185 /*
   197 -(void) gameHasEndedWithStats:(NSArray *)stats {
   186 -(void) gameHasEndedWithStats:(NSArray *)stats {