cocoaTouch/otherSrc/CommodityFunctions.m
author koda
Tue, 13 Apr 2010 22:45:46 +0000
changeset 3340 96dd168b080b
parent 3339 d558bc5a73c5
child 3352 ac5d14a35482
permissions -rw-r--r--
fix all of what was committed before
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     1
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     2
//  CommodityFunctions.m
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     3
//  HedgewarsMobile
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     4
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     5
//  Created by Vittorio on 08/04/10.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     7
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     8
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     9
#import "CommodityFunctions.h"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    10
#import "SDL_uikitappdelegate.h"
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    11
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    12
void createTeamNamed (NSString *nameWithoutExt) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    13
    NSString *teamsDirectory = TEAMS_DIRECTORY();
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    14
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    15
    if (![[NSFileManager defaultManager] fileExistsAtPath: teamsDirectory]) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    16
        [[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    17
                                  withIntermediateDirectories:NO 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    18
                                                   attributes:nil 
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    19
                                                        error:NULL];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    20
    }
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    21
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    22
    NSMutableArray *hedgehogs = [[NSMutableArray alloc] initWithCapacity: MAX_HOGS];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    23
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    24
    for (int i = 0; i < MAX_HOGS; i++) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    25
        NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents: 3335
diff changeset
    26
	NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health", [NSNumber numberWithInt:0],@"level",
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    27
                             hogName,@"hogname", @"NoHat",@"hat", nil];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    28
        [hogName release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    29
        [hedgehogs addObject:hog];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    30
        [hog release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    31
    }
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    32
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    33
    NSDictionary *theTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"0",@"hash", nameWithoutExt,@"teamname",
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    34
                             @"Statue",@"grave", @"Plane",@"fort", @"Default",@"voicepack",
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    35
                             @"hedgewars",@"flag", hedgehogs,@"hedgehogs", nil];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    36
    [hedgehogs release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    37
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    38
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist", teamsDirectory, nameWithoutExt];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    39
    NSLog(@"%@",teamFile);
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    40
    [theTeam writeToFile:teamFile atomically:YES];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    41
    [teamFile release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    42
    [theTeam release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    43
}
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    44
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    45
UIImage *mergeHogHatSprites (UIImage *firstImage, UIImage *secondImage) {
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    46
    UIGraphicsBeginImageContext(firstImage.size);
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    47
    [firstImage drawAtPoint:CGPointMake(0,0)];
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    48
    [secondImage drawAtPoint:CGPointMake(0,-5)];
3330
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    49
    UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    50
    UIGraphicsEndImageContext();
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    51
    return resultImage; // autoreleased
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    52
}
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    53
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    54
BOOL rotationManager (UIInterfaceOrientation interfaceOrientation) {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    55
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    56
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    57
    else
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    58
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    59
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3330
diff changeset
    60
}