cocoaTouch/otherSrc/CommodityFunctions.m
author koda
Sat, 10 Apr 2010 01:09:29 +0000
changeset 3330 987ec27b6042
parent 3325 652a8ebdf667
child 3335 2520ee7a5484
permissions -rw-r--r--
add support for modifying the name of the team nicer presentation of hog+hat
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"
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    10
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];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    26
        NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health", @"0",@"level",
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
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    45
UIImage *mergeTwoImages (UIImage *firstImage, UIImage *secondImage) {
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)];
987ec27b6042 add support for modifying the name of the team
koda
parents: 3325
diff changeset
    48
    [secondImage drawAtPoint:CGPointMake(0,-4)];
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
}