80 lines
1.6 KiB
Objective-C
80 lines
1.6 KiB
Objective-C
/*
|
|
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
|
* This file is part of OpenRA, which is free software. It is made
|
|
* available to you under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation. For more information,
|
|
* see LICENSE.
|
|
*/
|
|
|
|
#import "JSBridge.h"
|
|
#import "Controller.h"
|
|
|
|
static JSBridge *SharedInstance;
|
|
|
|
@implementation JSBridge
|
|
@synthesize methods;
|
|
|
|
+ (JSBridge *)sharedInstance
|
|
{
|
|
if (SharedInstance == nil)
|
|
SharedInstance = [[JSBridge alloc] init];
|
|
|
|
return SharedInstance;
|
|
}
|
|
|
|
+ (NSString *)webScriptNameForSelector:(SEL)sel
|
|
{
|
|
return [[[JSBridge sharedInstance] methods] objectForKey:NSStringFromSelector(sel)];
|
|
}
|
|
|
|
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)sel
|
|
{
|
|
return [[[JSBridge sharedInstance] methods] objectForKey:NSStringFromSelector(sel)] == nil;
|
|
}
|
|
|
|
-(id)init
|
|
{
|
|
self = [super init];
|
|
if (self != nil)
|
|
{
|
|
methods = [[NSDictionary dictionaryWithObjectsAndKeys:
|
|
@"launchCurrentMod", NSStringFromSelector(@selector(launchCurrentMod)),
|
|
@"log", NSStringFromSelector(@selector(log:)),
|
|
@"fileExistsInMod", NSStringFromSelector(@selector(fileExists:inMod:)),
|
|
nil] retain];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)setController:(Controller *)aController
|
|
{
|
|
controller = [aController retain];
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
[controller release]; controller = nil;
|
|
[super dealloc];
|
|
}
|
|
|
|
#pragma mark JS methods
|
|
|
|
- (void)launchCurrentMod
|
|
{
|
|
NSLog(@"launchcurrent");
|
|
[controller launchGame];
|
|
}
|
|
|
|
- (void)log:(NSString *)message
|
|
{
|
|
NSLog(@"js: %@",message);
|
|
}
|
|
|
|
- (BOOL)fileExists:(NSString *)aFile inMod:(NSString *)aMod
|
|
{
|
|
NSLog(@"File %@ exists in mod %@",aFile, aMod);
|
|
return NO;
|
|
}
|
|
|
|
@end
|