Permalink
Browse files

Added StoreInfo

Gathering information about game assets on runtime.
Fixed UI issues on iPhone
  • Loading branch information...
1 parent 95bade5 commit 438cefe1e7a722eb52b54984d7ce779b82fe357d @refaelos refaelos committed Oct 28, 2012
View
3 .gitignore
@@ -62,7 +62,8 @@ cocos2dx-store/proj.android/.settings
cocos2dx-store/proj.android/gen
cocos2dx-store/proj.android/bin
cocos2dx-store/proj.android/out
-
+cocos2dx-store/proj.android/assets/iphone
+cocos2dx-store/proj.android/assets/iphonehd
.idea/workspace.xml
cocos2dx-store/proj.android/.idea/workspace.xml
View
16 cocos2dx-store.xcodeproj/project.pbxproj
@@ -55,7 +55,7 @@
C069308F163C86D60037E975 /* libcocos2dx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C0B04372163C84860015400E /* libcocos2dx.a */; };
C0693091163C876C0037E975 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C0693090163C876C0037E975 /* libz.dylib */; };
C0693093163C87760037E975 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C0693092163C87760037E975 /* libxml2.dylib */; };
- C0B042D5163BFD150015400E /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C0B042D4163BFD150015400E /* Info.plist */; };
+ C06930A1163D86E30037E975 /* cocos2dx_StoreInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = C06930A0163D86E30037E975 /* cocos2dx_StoreInfo.mm */; };
C0B042DC163BFD2B0015400E /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = C0B042D6163BFD2B0015400E /* Icon-72.png */; };
C0B042DD163BFD2B0015400E /* Icon-Small-50.png in Resources */ = {isa = PBXBuildFile; fileRef = C0B042D7163BFD2B0015400E /* Icon-Small-50.png */; };
C0B042DE163BFD2B0015400E /* Icon-Small.png in Resources */ = {isa = PBXBuildFile; fileRef = C0B042D8163BFD2B0015400E /* Icon-Small.png */; };
@@ -66,7 +66,6 @@
C0B042F2163BFE960015400E /* MainScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0B042E9163BFE960015400E /* MainScene.cpp */; };
C0B042F3163BFE960015400E /* StoreAScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0B042EC163BFE960015400E /* StoreAScene.cpp */; };
C0B042F4163BFE960015400E /* StoreBScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0B042EE163BFE960015400E /* StoreBScene.cpp */; };
- C0B04305163C067F0015400E /* AnalyticXStringUtil.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0B04304163C067F0015400E /* AnalyticXStringUtil.mm */; };
C0B04308163C59700015400E /* iOSHelper.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0B04306163C59700015400E /* iOSHelper.mm */; };
C0B04310163C5DDE0015400E /* MuffinRushAssets.m in Sources */ = {isa = PBXBuildFile; fileRef = C0B0430F163C5DDE0015400E /* MuffinRushAssets.m */; };
C0B0431B163C7B250015400E /* cocos2dx_StoreInventory.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0B0431A163C7B250015400E /* cocos2dx_StoreInventory.mm */; };
@@ -170,6 +169,8 @@
C031BE341637FE84005F73E3 /* cocos2dx_StoreInventory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cocos2dx_StoreInventory.h; path = Classes/cocos2dx_StoreInventory.h; sourceTree = "<group>"; };
C0693090163C876C0037E975 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
C0693092163C87760037E975 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
+ C0693095163D27730037E975 /* cocos2dx_StoreInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cocos2dx_StoreInfo.h; path = Classes/cocos2dx_StoreInfo.h; sourceTree = "<group>"; };
+ C06930A0163D86E30037E975 /* cocos2dx_StoreInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = cocos2dx_StoreInfo.mm; path = ios/cocos2dx_StoreInfo.mm; sourceTree = "<group>"; };
C0B042D3163BFCB50015400E /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = "<group>"; };
C0B042D4163BFD150015400E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Resources/Info.plist; sourceTree = "<group>"; };
C0B042D6163BFD2B0015400E /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-72.png"; path = "ios/Resources/Icon-72.png"; sourceTree = "<group>"; };
@@ -189,8 +190,6 @@
C0B042EE163BFE960015400E /* StoreBScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StoreBScene.cpp; path = Classes/StoreBScene.cpp; sourceTree = "<group>"; };
C0B042EF163BFE960015400E /* StoreBScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StoreBScene.h; path = Classes/StoreBScene.h; sourceTree = "<group>"; };
C0B042F5163C023A0015400E /* Includes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Includes.h; path = Classes/Includes.h; sourceTree = "<group>"; };
- C0B04303163C067F0015400E /* AnalyticXStringUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AnalyticXStringUtil.h; path = Classes/AnalyticXStringUtil.h; sourceTree = "<group>"; };
- C0B04304163C067F0015400E /* AnalyticXStringUtil.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AnalyticXStringUtil.mm; path = Classes/AnalyticXStringUtil.mm; sourceTree = "<group>"; };
C0B04306163C59700015400E /* iOSHelper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = iOSHelper.mm; path = ios/iOSHelper.mm; sourceTree = "<group>"; };
C0B04307163C59700015400E /* iOSHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = iOSHelper.h; path = ios/iOSHelper.h; sourceTree = "<group>"; };
C0B0430E163C5DDE0015400E /* MuffinRushAssets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MuffinRushAssets.h; path = ios/MuffinRushAssets.h; sourceTree = "<group>"; };
@@ -303,12 +302,11 @@
C031BAA41635BDBA005F73E3 /* RootViewController.h */,
C031BAA51635BDBA005F73E3 /* RootViewController.mm */,
C031BAA71635BDBA005F73E3 /* main.m */,
- C0B04303163C067F0015400E /* AnalyticXStringUtil.h */,
- C0B04304163C067F0015400E /* AnalyticXStringUtil.mm */,
C0B04306163C59700015400E /* iOSHelper.mm */,
C0B04307163C59700015400E /* iOSHelper.h */,
C031BD471635C4C7005F73E3 /* cocos2dx_StoreController.mm */,
C0B0431A163C7B250015400E /* cocos2dx_StoreInventory.mm */,
+ C06930A0163D86E30037E975 /* cocos2dx_StoreInfo.mm */,
);
name = ios;
sourceTree = "<group>";
@@ -335,9 +333,10 @@
C0B042EF163BFE960015400E /* StoreBScene.h */,
C031BD251635BDBD005F73E3 /* AppDelegate.h */,
C031BD261635BDBD005F73E3 /* AppDelegate.cpp */,
+ C0B042F5163C023A0015400E /* Includes.h */,
C031BD4A1635C551005F73E3 /* cocos2dx_StoreController.h */,
C031BE341637FE84005F73E3 /* cocos2dx_StoreInventory.h */,
- C0B042F5163C023A0015400E /* Includes.h */,
+ C0693095163D27730037E975 /* cocos2dx_StoreInfo.h */,
C0B042E8163BFE960015400E /* cocos2dx_InsufficientFundsException.h */,
C0B042EB163BFE960015400E /* cocos2dx_NotEnoughGoodsException.h */,
C031BE3116370E9B005F73E3 /* cocos2dx_VirtualItemNotFoundException.h */,
@@ -544,7 +543,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- C0B042D5163BFD150015400E /* Info.plist in Resources */,
C0B042DC163BFD2B0015400E /* Icon-72.png in Resources */,
C0B042DD163BFD2B0015400E /* Icon-Small-50.png in Resources */,
C0B042DE163BFD2B0015400E /* Icon-Small.png in Resources */,
@@ -601,11 +599,11 @@
C0B042F2163BFE960015400E /* MainScene.cpp in Sources */,
C0B042F3163BFE960015400E /* StoreAScene.cpp in Sources */,
C0B042F4163BFE960015400E /* StoreBScene.cpp in Sources */,
- C0B04305163C067F0015400E /* AnalyticXStringUtil.mm in Sources */,
C0B04308163C59700015400E /* iOSHelper.mm in Sources */,
C0B04310163C5DDE0015400E /* MuffinRushAssets.m in Sources */,
C0B0431B163C7B250015400E /* cocos2dx_StoreInventory.mm in Sources */,
C0B0431E163C7C980015400E /* StoreInventory.m in Sources */,
+ C06930A1163D86E30037E975 /* cocos2dx_StoreInfo.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
22 cocos2dx-store/Classes/AnalyticXStringUtil.h
@@ -1,22 +0,0 @@
-//
-// AnalyticXStringUtil.h
-// AnalyticX
-//
-// Created by diwwu on 5/10/12.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
-//
-
-#ifndef AnalyticX_AnalyticXStringUtil_h
-#define AnalyticX_AnalyticXStringUtil_h
-
-#include "cocos2d.h"
-
-@interface AnalyticXStringUtil:NSObject
-
-+ (NSString *)nsstringFromCString:(const char *)cstring;
-+ (const char *)cstringFromNSString:(NSString *)nsstring;
-+ (NSDictionary *)nsDictionaryFromCCDictionary:(cocos2d::CCDictionary *)ccDictionary;
-
-@end
-
-#endif
View
54 cocos2dx-store/Classes/AnalyticXStringUtil.mm
@@ -1,54 +0,0 @@
-//
-// AnalyticXStringUtil.cpp
-// AnalyticX
-//
-// Created by diwwu on 5/10/12.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
-//
-
-#import "AnalyticXStringUtil.h"
-
-@implementation AnalyticXStringUtil
-
-+ (NSString *)nsstringFromCString:(const char *)cstring {
- if (cstring == NULL) {
- return NULL;
- }
-
- NSString * nsstring = [[NSString alloc] initWithBytes:cstring length:strlen(cstring) encoding:NSUTF8StringEncoding];
- return [nsstring autorelease];
-}
-+ (const char *)cstringFromNSString:(NSString *)nsstring {
-
- if (nsstring == NULL) {
- return NULL;
- }
-
- return [nsstring UTF8String];
-}
-+ (NSDictionary *)nsDictionaryFromCCDictionary:(cocos2d::CCDictionary *)ccDictionary {
- if (ccDictionary == NULL) {
- return NULL;
- } else if (ccDictionary->allKeys() == NULL) {
- return NULL;
- } else if (ccDictionary->allKeys()->count() <= 0) {
- return NULL;
- }
-
- cocos2d::CCLog("1");
-
- NSMutableDictionary *nsDict = [NSMutableDictionary dictionaryWithCapacity:ccDictionary->allKeys()->count()];
-
- cocos2d::CCLog("2");
-
- for (int i = 0; i < ccDictionary->allKeys()->count(); i++) {
- cocos2d::CCLog("3");
-
- [nsDict setValue:[AnalyticXStringUtil nsstringFromCString:((cocos2d::CCString *)ccDictionary->objectForKey(((cocos2d::CCString *)ccDictionary->allKeys()->objectAtIndex(i))->getCString()))->getCString()] forKey:[AnalyticXStringUtil nsstringFromCString:((cocos2d::CCString *)ccDictionary->allKeys()->objectAtIndex(i))->getCString()]];
- }
-
- return nsDict;
-}
-
-
-@end
View
16 cocos2dx-store/Classes/AppDelegate.cpp
@@ -36,15 +36,17 @@ bool AppDelegate::applicationDidFinishLaunching() {
{
// iphone
- if (pDirector->enableRetinaDisplay(true))
- {
+// if (pDirector->enableRetinaDisplay(true))
+// {
// iphone hd
CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd");
- }
- else
- {
- CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone");
- }
+// }
+// else
+// {
+// CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone");
+// }
+
+ CCEGLView::sharedOpenGLView()->setDesignResolutionSize(720, 1280, kResolutionNoBorder);
}
else
{
View
257 cocos2dx-store/Classes/JniHelpers.cpp
@@ -0,0 +1,257 @@
+//
+// JniHelpers.cpp
+// cocos2dx-store
+//
+// Created by Refael Dakar on 10/28/12.
+//
+//
+
+#include "JniHelpers.h"
+#include <jni.h>
+#include "platform/android/jni/JniHelper.h"
+#include <android/log.h>
+
+void JniHelpers::jniCommonVoidCall(const char* methodName, const char* classPath) {
+ cocos2d::JniMethodInfo minfo;
+
+ bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "()V");
+
+ if (!isHave) {
+ //do nothing
+ } else {
+ minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
+ }
+}
+
+void JniHelpers::jniCommonVoidCall(const char* methodName, const char* classPath, bool arg0) {
+ cocos2d::JniMethodInfo minfo;
+
+ bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Z)V");
+
+ if (!isHave) {
+ //do nothing
+ } else {
+ minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, arg0);
+ }
+}
+
+void JniHelpers::jniCommonVoidCall(const char* methodName, const char* classPath, const char* arg0)
+ throw (cocos2dx_VirtualItemNotFoundException&, cocos2dx_NotEnoughGoodsException&, cocos2dx_InsufficientFundsException&) {
+ cocos2d::JniMethodInfo minfo;
+
+ bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo, classPath, methodName, "(Ljava/lang/String;)V");
+
+ if (!isHave) {
+ //do nothing
+ } else {
+ jstring stringArg0 = minfo.env->NewStringUTF(arg0);
+
+ minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
+
+ minfo.env->DeleteLocalRef(stringArg0);
+
+ if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
+ jthrowable exceptionObj = minfo.env->ExceptionOccurred();
+ minfo.env->ExceptionClear();
+
+ jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
+ if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
+
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+
+ vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/NotEnoughGoodsException", minfo.env);
+ if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought NotEnoughGoodsException!");
+
+ throw cocos2dx_NotEnoughGoodsException();
+ }
+
+ vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/InsufficientFundsException", minfo.env);
+ if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought InsufficientFundsException!");
+
+ throw cocos2dx_InsufficientFundsException();
+ }
+ }
+ }
+}
+
+int JniHelpers::jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0)
+ throw (cocos2dx_VirtualItemNotFoundException&) {
+ cocos2d::JniMethodInfo minfo;
+
+ bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;)I");
+
+ if (!isHave) {
+ //do nothing
+ } else {
+ jstring stringArg0 = minfo.env->NewStringUTF(arg0);
+
+ jint ret = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0);
+
+ minfo.env->DeleteLocalRef(stringArg0);
+
+ if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
+ jthrowable exceptionObj = minfo.env->ExceptionOccurred();
+ minfo.env->ExceptionClear();
+
+ jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
+ if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
+
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+ }
+
+ return (int)ret;
+ }
+
+ return 0;
+}
+
+int JniHelpers::jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0, int arg1)
+ throw (cocos2dx_VirtualItemNotFoundException&) {
+ cocos2d::JniMethodInfo minfo;
+
+ bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;I)I");
+
+ if (!isHave) {
+ //do nothing
+ } else {
+ jstring stringArg0 = minfo.env->NewStringUTF(arg0);
+
+ jint ret = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0, arg1);
+
+ minfo.env->DeleteLocalRef(stringArg0);
+
+ if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
+ jthrowable exceptionObj = minfo.env->ExceptionOccurred();
+ minfo.env->ExceptionClear();
+
+ jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
+ if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
+
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+ }
+
+ return (int)ret;
+ }
+
+ return 0;
+}
+
+int JniHelpers::jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0, const char* arg1)
+ throw (cocos2dx_VirtualItemNotFoundException&) {
+ cocos2d::JniMethodInfo minfo;
+
+ bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;Ljava/lang/String;)I");
+
+ if (!isHave) {
+ //do nothing
+ } else {
+ jstring stringArg0 = minfo.env->NewStringUTF(arg0);
+ jstring stringArg1 = minfo.env->NewStringUTF(arg1);
+
+ jint ret = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0, stringArg1);
+
+ minfo.env->DeleteLocalRef(stringArg0);
+ minfo.env->DeleteLocalRef(stringArg1);
+
+ if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
+ jthrowable exceptionObj = minfo.env->ExceptionOccurred();
+ minfo.env->ExceptionClear();
+
+ jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
+ if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
+
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+ }
+
+ return (int)ret;
+ }
+
+ return 0;
+}
+
+string JniHelpers::jniCommonStringCall(const char* methodName, const char* classPath, const char* arg0)
+ throw (cocos2dx_VirtualItemNotFoundException&) {
+ cocos2d::JniMethodInfo minfo;
+
+ bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;)Ljava/lang/String;");
+
+ if (!isHave) {
+ //do nothing
+ } else {
+ jstring stringArg0 = minfo.env->NewStringUTF(arg0);
+
+ jstring retString = (jstring) minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID, stringArg0);
+
+ minfo.env->DeleteLocalRef(stringArg0);
+
+ const char *nativeString = minfo.env->GetStringUTFChars(retString, 0);
+ string ret(nativeString);
+ minfo.env->ReleaseStringUTFChars(retString, nativeString);
+
+ if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
+ jthrowable exceptionObj = minfo.env->ExceptionOccurred();
+ minfo.env->ExceptionClear();
+
+ jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
+ if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
+
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+ }
+
+ return ret;
+ }
+
+ return NULL;
+}
+
+double JniHelpers::jniCommonDoubleCall(const char* methodName, const char* classPath, const char* arg0)
+ throw (cocos2dx_VirtualItemNotFoundException&) {
+ cocos2d::JniMethodInfo minfo;
+
+ bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,classPath,methodName, "(Ljava/lang/String;)D");
+
+ if (!isHave) {
+ //do nothing
+ } else {
+ jstring stringArg0 = minfo.env->NewStringUTF(arg0);
+
+ jdouble ret = minfo.env->CallStaticDoubleMethod(minfo.classID, minfo.methodID, stringArg0);
+
+ minfo.env->DeleteLocalRef(stringArg0);
+
+ if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
+ jthrowable exceptionObj = minfo.env->ExceptionOccurred();
+ minfo.env->ExceptionClear();
+
+ jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
+ if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
+ __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
+
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+ }
+
+ return (double)ret;
+ }
+
+ return 0;
+}
+
View
34 cocos2dx-store/Classes/JniHelpers.h
@@ -0,0 +1,34 @@
+//
+// JniHelpers.h
+// cocos2dx-store
+//
+// Created by Refael Dakar on 10/28/12.
+//
+//
+
+#ifndef __cocos2dx_store__JniHelpers__
+#define __cocos2dx_store__JniHelpers__
+
+#include "cocos2dx_VirtualItemNotFoundException.h"
+#include "cocos2dx_InsufficientFundsException.h"
+#include "cocos2dx_NotEnoughGoodsException.h"
+
+class JniHelpers {
+public:
+ static void jniCommonVoidCall(const char* methodName, const char* classPath);
+ static void jniCommonVoidCall(const char* methodName, const char* classPath, bool arg0);
+ static void jniCommonVoidCall(const char* methodName, const char* classPath, const char* arg0)
+ throw(cocos2dx_VirtualItemNotFoundException&, cocos2dx_NotEnoughGoodsException&, cocos2dx_InsufficientFundsException&);
+ static int jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0, int arg1)
+ throw (cocos2dx_VirtualItemNotFoundException&);
+ static int jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0)
+ throw (cocos2dx_VirtualItemNotFoundException&);
+ static int jniCommonIntCall(const char* methodName, const char* classPath, const char* arg0, const char* arg1)
+ throw (cocos2dx_VirtualItemNotFoundException&);
+ static string jniCommonStringCall(const char* methodName, const char* classPath, const char* arg0)
+ throw (cocos2dx_VirtualItemNotFoundException&);
+ static double jniCommonDoubleCall(const char* methodName, const char* classPath, const char* arg0)
+ throw (cocos2dx_VirtualItemNotFoundException&);
+};
+
+#endif /* defined(__cocos2dx_store__JniHelpers__) */
View
25 cocos2dx-store/Classes/StoreAScene.cpp
@@ -4,6 +4,7 @@
#include "StoreBScene.h"
#include "cocos2dx_StoreController.h"
#include "cocos2dx_StoreInventory.h"
+#include "cocos2dx_StoreInfo.h"
#include "Includes.h"
#include <string>
@@ -86,10 +87,10 @@ bool StoreAScene::init()
// In Game Menu
CCMenu* menu = CCMenu::create(getMoreItem, backItem, NULL);
- createListViewItem(origin, menu, visibleSize, 0, "fruit_cake.png", "Fruit Cake", "Customers buy a double portion on each purchase of this cake", 225, 0);
- createListViewItem(origin, menu, visibleSize, 1, "pavlova.png", "Pavlova", "Gives customers a sugar rush and they call their friends", 175, 0);
- createListViewItem(origin, menu, visibleSize, 2, "cream_cup.png", "Cream Cup", "Increase bakery reputation with this original pastry", 50, 0);
- createListViewItem(origin, menu, visibleSize, 3, "chocolate_cake.png", "Chocolate Cake", "A classic cake to maximize customer satisfaction", 250, 0);
+ createListViewItem(origin, menu, visibleSize, 0, "fruit_cake.png");
+ createListViewItem(origin, menu, visibleSize, 1, "pavlova.png");
+ createListViewItem(origin, menu, visibleSize, 2, "cream_cup.png");
+ createListViewItem(origin, menu, visibleSize, 3, "chocolate_cake.png");
menu->setPosition(CCPointZero);
this->addChild(menu);
@@ -149,12 +150,23 @@ void StoreAScene::menuChooseCallback(CCObject* pSender)
}
}
-void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img, const char* name, const char* info, int price, int balance) {
+void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img) {
GameMenuItem *pChooseItem = GameMenuItem::itemWithLabel(
CCSprite::create("button.png"),
this,
menu_selector(StoreAScene::menuChooseCallback));
+ char itemId[512];
+ snprintf(itemId, sizeof(itemId), itemIdFromTag(tag));
+
+ // TODO: exception handling ..
+ string nameS = cocos2dx_StoreInfo::getGoodName(itemId);
+ string infoS = cocos2dx_StoreInfo::getGoodDescription(itemId);
+ int price = cocos2dx_StoreInfo::getGoodPriceForCurrency(itemId, "currency_muffin");
+ int balance = 0;
+ const char * name = nameS.c_str();
+ const char * info = infoS.c_str();
+
float yOffset = - 200;
pChooseItem->setPosition(ccp(origin.x + visibleSize.width/2, yOffset + origin.y + visibleSize.height - 100 - (tag * pChooseItem->boundingBox().size.height)));
@@ -194,9 +206,6 @@ void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visi
menu->addChild(pChooseItem, 1);
- char itemId[512];
- snprintf(itemId, sizeof(itemId), itemIdFromTag(tag));
-
setPriceBalanceLabel(itemId);
}
View
2 cocos2dx-store/Classes/StoreAScene.h
@@ -8,7 +8,7 @@ USING_NS_CC;
class StoreAScene : public cocos2d::CCLayerColor
{
private:
- void createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img, const char* name, const char* info, int price, int balance);
+ void createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img);
const char* itemIdFromTag(int tag);
static int tagFromItemId(const char* itemId);
View
63 cocos2dx-store/Classes/StoreBScene.cpp
@@ -3,6 +3,7 @@
#include "StoreAScene.h"
#include "cocos2dx_StoreInventory.h"
#include "cocos2dx_StoreController.h"
+#include "cocos2dx_StoreInfo.h"
#include "Includes.h"
#include <string>
@@ -75,11 +76,11 @@ bool StoreBScene::init()
// In Game Menu
CCMenu* menu = CCMenu::create(backItem, NULL);
- createListViewItem(origin, menu, visibleSize, 0, "no_ads.png", "Remove Ads!", "Test purchase of MANAGED item.", 5.99);
- createListViewItem(origin, menu, visibleSize, 1, "muffins01.png", "10 Muffins", "Test refund of an item", 0.99);
- createListViewItem(origin, menu, visibleSize, 2, "muffins02.png", "50 Muffins", "Test cancellation of an item", 1.99);
- createListViewItem(origin, menu, visibleSize, 3, "muffins03.png", "400 Muffins", "Test purchase of an item", 4.99);
- createListViewItem(origin, menu, visibleSize, 4, "muffins04.png", "1000 Muffins", "Test item unavailable", 8.99);
+ createListViewItem(origin, menu, visibleSize, 0, "no_ads.png");
+ createListViewItem(origin, menu, visibleSize, 1, "muffins01.png");
+ createListViewItem(origin, menu, visibleSize, 2, "muffins02.png");
+ createListViewItem(origin, menu, visibleSize, 3, "muffins03.png");
+ createListViewItem(origin, menu, visibleSize, 4, "muffins04.png");
menu->setPosition(CCPointZero);
this->addChild(menu);
@@ -143,12 +144,34 @@ void StoreBScene::setCurrencyBalanceLabel() {
pLabelBalance->setString(convert.str().c_str());
}
-void StoreBScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img, const char* name, const char* info, float price) {
+void StoreBScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img) {
GameMenuItem *pChooseItem = GameMenuItem::itemWithLabel(
CCSprite::create("button.png"),
this,
menu_selector(StoreBScene::menuChooseCallback));
+ char itemId[512];
+ snprintf(itemId, sizeof(itemId), itemIdFromTag(tag));
+
+ char name[512];
+ char info[512];
+ double price = 0;
+ int balance = 0;
+ if (strcmp (itemId,"ERROR") == 0) {
+ snprintf(name, sizeof(name), "Remove Ads!");
+ snprintf(info, sizeof(info), "Test purchase of MANAGED item.");
+ price = 5.99f;
+ }
+ else {
+ // TODO: exception handling ..
+ string nameS = cocos2dx_StoreInfo::getPackName(itemId);
+ string infoS = cocos2dx_StoreInfo::getPackDescription(itemId);
+ price = cocos2dx_StoreInfo::getPackPrice(itemId);
+
+ snprintf(name, sizeof(name), nameS.c_str());
+ snprintf(info, sizeof(info), infoS.c_str());
+ }
+
float yOffset = - 200;
pChooseItem->setPosition(ccp(origin.x + visibleSize.width/2, yOffset + origin.y + visibleSize.height - 100 - (tag * pChooseItem->boundingBox().size.height)));
@@ -190,23 +213,37 @@ void StoreBScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visi
}
const char* StoreBScene::productIdFromTag(int tag) {
+
+ char itemId[512];
+ snprintf(itemId, sizeof(itemId), itemIdFromTag(tag));
+
+ if (strcmp (itemId,"ERROR") == 0) {
+ return "no_ads";
+ }
+ else {
+ // TODO: exception handling ..
+ string p = cocos2dx_StoreInfo::getPackProductId(itemId);
+ return p.c_str();
+ }
+
+ return "ERROR";
+}
+
+const char* StoreBScene::itemIdFromTag(int tag) {
switch (tag)
{
- case 0: return "no_ads";
+ case 1: return "muffins_10";
break;
- case 1: return "android.test.refunded";
+ case 2: return "muffins_50";
break;
- case 2: return "android.test.canceled";
+ case 3: return "muffins_400";
break;
- case 3: return "android.test.purchased";
+ case 4: return "muffins_1000";
break;
- case 4: return "android.test.item_unavailable";
- break;
default: return "ERROR";
break;
}
return "ERROR";
}
-
View
5 cocos2dx-store/Classes/StoreBScene.h
@@ -9,8 +9,9 @@ class StoreBScene : public cocos2d::CCLayerColor
{
private:
const char* productIdFromTag(int tag);
- void createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img, const char* name, const char* info, float price);
-
+ void createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img);
+ const char* itemIdFromTag(int tag);
+
static CCLabelTTF* pLabelBalance;
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
View
237 cocos2dx-store/Classes/cocos2dx_StoreController.cpp
@@ -7,224 +7,69 @@
//
#include "cocos2dx_StoreController.h"
-
-#include <jni.h>
-#include "platform/android/jni/JniHelper.h"
-#include <android/log.h>
+#include "JniHelpers.h"
void cocos2dx_StoreController::storeOpening() {
- cocos2d::JniMethodInfo minfo;
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","storeOpening", "()V");
-
- if (!isHave) {
- //do nothing
- } else {
- minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
- }
+ JniHelpers::jniCommonVoidCall(
+ "storeOpening",
+ "com/soomla/store/StoreControllerBridge"
+ );
+
}
void cocos2dx_StoreController::storeClosing() {
- cocos2d::JniMethodInfo minfo;
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","storeClosing", "()V");
-
- if (!isHave) {
- //do nothing
- } else {
- minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
- }
+ JniHelpers::jniCommonVoidCall(
+ "storeClosing",
+ "com/soomla/store/StoreControllerBridge"
+ );
+
}
void cocos2dx_StoreController::initialize(bool debug) {
- cocos2d::JniMethodInfo minfo;
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","initialize", "(Z)V");
-
- if (!isHave) {
- //do nothing
- } else {
- minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, debug);
- }
+ JniHelpers::jniCommonVoidCall(
+ "initialize",
+ "com/soomla/store/StoreControllerBridge",
+ debug
+ );
}
void cocos2dx_StoreController::buyCurrencyPack(string productId) throw(cocos2dx_VirtualItemNotFoundException&){
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting buyCurrencyPack");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","buyCurrencyPack", "(Ljava/lang/String;)V");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(productId.c_str());
-
- minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "buyCurrencyPack returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
- }
+ JniHelpers::jniCommonVoidCall(
+ "buyCurrencyPack",
+ "com/soomla/store/StoreControllerBridge",
+ productId.c_str()
+ );
}
void cocos2dx_StoreController::buyVirtualGood(string itemId) throw (cocos2dx_VirtualItemNotFoundException&, cocos2dx_InsufficientFundsException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting buyVirtualGood");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","buyVirtualGood", "(Ljava/lang/String;)V");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(itemId.c_str());
-
- minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "buyVirtualGood returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
-
- vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/InsufficientFundsException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought InsufficientFundsException!");
-
- throw cocos2dx_InsufficientFundsException();
- }
- }
- }
+ JniHelpers::jniCommonVoidCall(
+ "buyVirtualGood",
+ "com/soomla/store/StoreControllerBridge",
+ itemId.c_str()
+ );
}
void cocos2dx_StoreController::buyManagedItem(string productId) throw(cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting buyManagedItem");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","buyManagedItem", "(Ljava/lang/String;)V");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(productId.c_str());
-
- minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "buyManagedItem returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
- }
+ JniHelpers::jniCommonVoidCall(
+ "buyManagedItem",
+ "com/soomla/store/StoreControllerBridge",
+ productId.c_str()
+ );
}
void cocos2dx_StoreController::equipVirtualGood(string itemId) throw (cocos2dx_NotEnoughGoodsException&, cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting equipVirtualGood");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","equipVirtualGood", "(Ljava/lang/String;)V");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(itemId.c_str());
-
- minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "equipVirtualGood returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
-
- vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/NotEnoughGoodsException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought NotEnoughGoodsException!");
-
- throw cocos2dx_NotEnoughGoodsException();
- }
- }
- }
+ JniHelpers::jniCommonVoidCall(
+ "equipVirtualGood",
+ "com/soomla/store/StoreControllerBridge",
+ itemId.c_str()
+ );
}
void cocos2dx_StoreController::unequipVirtualGood(string itemId) throw(cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting unequipVirtualGood");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreControllerBridge","unequipVirtualGood", "(Ljava/lang/String;)V");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(itemId.c_str());
-
- minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, stringArg0);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "unequipVirtualGood returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
- }
+ JniHelpers::jniCommonVoidCall(
+ "unequipVirtualGood",
+ "com/soomla/store/StoreControllerBridge",
+ itemId.c_str()
+ );
}
-
View
2 cocos2dx-store/Classes/cocos2dx_StoreController.h
@@ -18,7 +18,7 @@
using namespace std;
class cocos2dx_StoreController {
-
+
public:
//iOS + Android
View
70 cocos2dx-store/Classes/cocos2dx_StoreInfo.cpp
@@ -0,0 +1,70 @@
+//
+// cocos2dx_StoreInfo.cpp
+// cocos2dx-store
+//
+// Created by Refael Dakar on 10/22/12.
+//
+//
+
+#include "cocos2dx_StoreInfo.h"
+#include "JniHelpers.h"
+
+string cocos2dx_StoreInfo::getPackProductId(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ return JniHelpers::jniCommonStringCall(
+ "getPackProductId",
+ "com/soomla/store/StoreInfoBridge",
+ itemId
+ );
+}
+
+string cocos2dx_StoreInfo::getPackName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ return JniHelpers::jniCommonStringCall(
+ "getPackName",
+ "com/soomla/store/StoreInfoBridge",
+ itemId
+ );
+}
+
+string cocos2dx_StoreInfo::getPackDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ return JniHelpers::jniCommonStringCall(
+ "getPackDescription",
+ "com/soomla/store/StoreInfoBridge",
+ itemId
+ );
+}
+
+double cocos2dx_StoreInfo::getPackPrice(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ return JniHelpers::jniCommonDoubleCall(
+ "getPackPrice",
+ "com/soomla/store/StoreInfoBridge",
+ itemId
+ );
+}
+
+string cocos2dx_StoreInfo::getGoodName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ return JniHelpers::jniCommonStringCall(
+ "getGoodName",
+ "com/soomla/store/StoreInfoBridge",
+ itemId
+ );
+}
+
+string cocos2dx_StoreInfo::getGoodDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ return JniHelpers::jniCommonStringCall(
+ "getGoodDescription",
+ "com/soomla/store/StoreInfoBridge",
+ itemId
+ );
+}
+
+int cocos2dx_StoreInfo::getGoodPriceForCurrency(const char* goodItemId, const char* currencyItemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ return JniHelpers::jniCommonIntCall(
+ "getGoodPriceForCurrency",
+ "com/soomla/store/StoreInfoBridge",
+ goodItemId,
+ currencyItemId
+ );
+}
+
+
+
View
32 cocos2dx-store/Classes/cocos2dx_StoreInfo.h
@@ -0,0 +1,32 @@
+//
+// cocos2dx_StoreInfo.h
+// cocos2dx-store
+//
+// Created by Refael Dakar on 10/28/12.
+//
+//
+
+#ifndef __cocos2dx_store__cocos2dx_StoreInfo__
+#define __cocos2dx_store__cocos2dx_StoreInfo__
+
+#include <iostream>
+#include "cocos2dx_VirtualItemNotFoundException.h"
+#include <string>
+
+using namespace std;
+
+class cocos2dx_StoreInfo {
+public:
+
+ static string getPackProductId(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
+ static string getPackName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
+ static string getPackDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
+ static double getPackPrice(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
+ static string getGoodName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
+ static string getGoodDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&);
+ static int getGoodPriceForCurrency(const char* goodItemId, const char* currencyItemId) throw (cocos2dx_VirtualItemNotFoundException&);
+
+};
+
+
+#endif /* defined(__cocos2dx_store__cocos2dx_StoreInfo__) */
View
243 cocos2dx-store/Classes/cocos2dx_StoreInventory.cpp
@@ -7,229 +7,56 @@
//
#include "cocos2dx_StoreInventory.h"
-#include <jni.h>
-#include "platform/android/jni/JniHelper.h"
-#include <android/log.h>
+#include "JniHelpers.h"
int cocos2dx_StoreInventory::getCurrencyBalance(string currencyItemId) throw (cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting getCurrencyBalance");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreInventoryBridge","getCurrencyBalance", "(Ljava/lang/String;)I");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(currencyItemId.c_str());
-
- jint balance = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "getCurrencyBalance returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
-
- return (int)balance;
- }
-
- return 0;
+ return JniHelpers::jniCommonIntCall(
+ "getCurrencyBalance",
+ "com/soomla/store/StoreInventoryBridge",
+ currencyItemId.c_str()
+ );
}
int cocos2dx_StoreInventory::addCurrencyAmount(string currencyItemId, int amount) throw (cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting addCurrencyAmount");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreInventoryBridge","addCurrencyAmount", "(Ljava/lang/String;I)I");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(currencyItemId.c_str());
-
- jint balance = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0, amount);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "addCurrencyAmount returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
-
- return (int)balance;
- }
-
- return 0;
+ return JniHelpers::jniCommonIntCall(
+ "addCurrencyAmount",
+ "com/soomla/store/StoreInventoryBridge",
+ currencyItemId.c_str(),
+ amount
+ );
}
int cocos2dx_StoreInventory::removeCurrencyAmount(string currencyItemId, int amount) throw (cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting removeCurrencyAmount");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreInventoryBridge","removeCurrencyAmount", "(Ljava/lang/String;I)I");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(currencyItemId.c_str());
-
- jint balance = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0, amount);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "removeCurrencyAmount returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
-
- return (int)balance;
- }
-
- return 0;
+ return JniHelpers::jniCommonIntCall(
+ "removeCurrencyAmount",
+ "com/soomla/store/StoreInventoryBridge",
+ currencyItemId.c_str(),
+ amount
+ );
}
int cocos2dx_StoreInventory::getGoodBalance(string goodItemId) throw (cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting getGoodBalance");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreInventoryBridge","getGoodBalance", "(Ljava/lang/String;)I");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(goodItemId.c_str());
-
- jint balance = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "getGoodBalance returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
-
- return (int)balance;
- }
-
- return 0;
+ return JniHelpers::jniCommonIntCall(
+ "getGoodBalance",
+ "com/soomla/store/StoreInventoryBridge",
+ goodItemId.c_str()
+ );
}
int cocos2dx_StoreInventory::addGoodAmount(string goodItemId, int amount) throw (cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting addGoodAmount");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreInventoryBridge","addGoodAmount", "(Ljava/lang/String;I)I");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(goodItemId.c_str());
-
- jint balance = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0, amount);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "addGoodAmount returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
-
- return (int)balance;
- }
-
- return 0;
+ return JniHelpers::jniCommonIntCall(
+ "addGoodAmount",
+ "com/soomla/store/StoreInventoryBridge",
+ goodItemId.c_str(),
+ amount
+ );
}
int cocos2dx_StoreInventory::removeGoodAmount(string goodItemId, int amount) throw (cocos2dx_VirtualItemNotFoundException&) {
- cocos2d::JniMethodInfo minfo;
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Starting removeGoodAmount");
-
- bool isHave = cocos2d::JniHelper::getStaticMethodInfo(minfo,"com/soomla/store/StoreInventoryBridge","removeGoodAmount", "(Ljava/lang/String;I)I");
-
- if (!isHave) {
- //do nothing
- } else {
- jstring stringArg0 = minfo.env->NewStringUTF(goodItemId.c_str());
-
- jint balance = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, stringArg0, amount);
-
- minfo.env->DeleteLocalRef(stringArg0);
-
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "removeGoodAmount returned");
-
- if(minfo.env->ExceptionCheck() == JNI_TRUE ) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "HAS EXCEPTION");
- jthrowable exceptionObj = minfo.env->ExceptionOccurred();
- minfo.env->ExceptionClear();
-
- jclass vinfEx = cocos2d::JniHelper::getClassID("com/soomla/store/exceptions/VirtualItemNotFoundException", minfo.env);
- if (minfo.env->IsInstanceOf(exceptionObj, vinfEx)) {
- __android_log_write(ANDROID_LOG_DEBUG, "SOOMLA JNI", "Cought VirtualItemNotFoundException!");
-
- throw cocos2dx_VirtualItemNotFoundException();
- }
- }
-
- return (int)balance;
- }
-
- return 0;
-
+ return JniHelpers::jniCommonIntCall(
+ "removeGoodAmount",
+ "com/soomla/store/StoreInventoryBridge",
+ goodItemId.c_str(),
+ amount
+ );
}
View
9 cocos2dx-store/ios/cocos2dx_StoreController.mm
@@ -5,7 +5,6 @@
#import "InsufficientFundsException.h"
#import "NotEnoughGoodsException.h"
#import "MuffinRushAssets.h"
-#import "AnalyticXStringUtil.h"
void cocos2dx_StoreController::storeOpening() {
[[StoreController getInstance] storeOpening];
@@ -25,7 +24,7 @@
void cocos2dx_StoreController::buyCurrencyPack(string productId) throw(cocos2dx_VirtualItemNotFoundException&) {
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:productId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:productId.c_str() length:strlen(productId.c_str()) encoding:NSUTF8StringEncoding];
[[StoreController getInstance] buyCurrencyPackWithProcuctId:str];
}
@catch (VirtualItemNotFoundException *exception) {
@@ -35,7 +34,7 @@
void cocos2dx_StoreController::buyVirtualGood(string itemId) throw (cocos2dx_VirtualItemNotFoundException&, cocos2dx_InsufficientFundsException&) {
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:itemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:itemId.c_str() length:strlen(itemId.c_str()) encoding:NSUTF8StringEncoding];
[[StoreController getInstance] buyVirtualGood:str];
}
@catch (VirtualItemNotFoundException *exception) {
@@ -55,7 +54,7 @@
void cocos2dx_StoreController::equipVirtualGood(string itemId) throw (cocos2dx_NotEnoughGoodsException&, cocos2dx_VirtualItemNotFoundException&) {
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:itemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:itemId.c_str() length:strlen(itemId.c_str()) encoding:NSUTF8StringEncoding];
[[StoreController getInstance] equipVirtualGood:str];
}
@catch (VirtualItemNotFoundException *exception) {
@@ -68,7 +67,7 @@
void cocos2dx_StoreController::unequipVirtualGood(string itemId) throw(cocos2dx_VirtualItemNotFoundException&) {
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:itemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:itemId.c_str() length:strlen(itemId.c_str()) encoding:NSUTF8StringEncoding];
[[StoreController getInstance] unequipVirtualGood:str];
}
@catch (VirtualItemNotFoundException *exception) {
View
93 cocos2dx-store/ios/cocos2dx_StoreInfo.mm
@@ -0,0 +1,93 @@
+//
+// cocos2dx_StoreInfo.cpp
+// cocos2dx-store
+//
+// Created by Refael Dakar on 10/28/12.
+//
+//
+
+#include "cocos2dx_StoreInfo.h"
+#import "VirtualCurrencyPack.h"
+#import "VirtualGood.h"
+#import "StoreInfo.h"
+#import "AppStoreItem.h"
+#import "VirtualItemNotFoundException.h"
+
+string cocos2dx_StoreInfo::getPackProductId(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ @try {
+ NSString * str = [[NSString alloc] initWithBytes:itemId length:strlen(itemId) encoding:NSUTF8StringEncoding];
+ VirtualCurrencyPack* pack = [[StoreInfo getInstance] currencyPackWithItemId:str];
+ return [pack.appstoreItem.productId UTF8String];
+ }
+ @catch (VirtualItemNotFoundException *exception) {
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+}
+
+string cocos2dx_StoreInfo::getPackName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ @try {
+ NSString * str = [[NSString alloc] initWithBytes:itemId length:strlen(itemId) encoding:NSUTF8StringEncoding];
+ VirtualCurrencyPack* pack = [[StoreInfo getInstance] currencyPackWithItemId:str];
+ return [pack.name UTF8String];
+ }
+ @catch (VirtualItemNotFoundException *exception) {
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+}
+
+string cocos2dx_StoreInfo::getPackDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ @try {
+ NSString * str = [[NSString alloc] initWithBytes:itemId length:strlen(itemId) encoding:NSUTF8StringEncoding];
+ VirtualCurrencyPack* pack = [[StoreInfo getInstance] currencyPackWithItemId:str];
+ return [pack.description UTF8String];
+ }
+ @catch (VirtualItemNotFoundException *exception) {
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+}
+
+double cocos2dx_StoreInfo::getPackPrice(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ @try {
+ NSString * str = [[NSString alloc] initWithBytes:itemId length:strlen(itemId) encoding:NSUTF8StringEncoding];
+ VirtualCurrencyPack* pack = [[StoreInfo getInstance] currencyPackWithItemId:str];
+ return pack.price;
+ }
+ @catch (VirtualItemNotFoundException *exception) {
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+}
+
+string cocos2dx_StoreInfo::getGoodName(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ @try {
+ NSString * str = [[NSString alloc] initWithBytes:itemId length:strlen(itemId) encoding:NSUTF8StringEncoding];
+ VirtualGood* good = [[StoreInfo getInstance] goodWithItemId:str];
+ return [good.name UTF8String];
+ }
+ @catch (VirtualItemNotFoundException *exception) {
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+}
+
+string cocos2dx_StoreInfo::getGoodDescription(const char* itemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ @try {
+ NSString * str = [[NSString alloc] initWithBytes:itemId length:strlen(itemId) encoding:NSUTF8StringEncoding];
+ VirtualGood* good = [[StoreInfo getInstance] goodWithItemId:str];
+ return [good.description UTF8String];
+ }
+ @catch (VirtualItemNotFoundException *exception) {
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+
+}
+
+int cocos2dx_StoreInfo::getGoodPriceForCurrency(const char* goodItemId, const char* currencyItemId) throw (cocos2dx_VirtualItemNotFoundException&) {
+ @try {
+ NSString * str1 = [[NSString alloc] initWithBytes:goodItemId length:strlen(goodItemId) encoding:NSUTF8StringEncoding];
+ NSString * str2 = [[NSString alloc] initWithBytes:currencyItemId length:strlen(currencyItemId) encoding:NSUTF8StringEncoding];
+ VirtualGood* good = [[StoreInfo getInstance] goodWithItemId:str1];
+ return [(NSNumber*)[good.currencyValues objectForKey:str2] intValue];
+ }
+ @catch (VirtualItemNotFoundException *exception) {
+ throw cocos2dx_VirtualItemNotFoundException();
+ }
+}
View
13 cocos2dx-store/ios/cocos2dx_StoreInventory.mm
@@ -8,12 +8,11 @@
#include "cocos2dx_StoreInventory.h"
#import "StoreInventory.h"
-#import "AnalyticXStringUtil.h"
#import "VirtualItemNotFoundException.h"
int cocos2dx_StoreInventory::getCurrencyBalance(string currencyItemId) throw (cocos2dx_VirtualItemNotFoundException&){
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:currencyItemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:currencyItemId.c_str() length:strlen(currencyItemId.c_str()) encoding:NSUTF8StringEncoding];
return [StoreInventory getCurrencyBalance:str];
}
@catch (VirtualItemNotFoundException *exception) {
@@ -23,7 +22,7 @@
int cocos2dx_StoreInventory::addCurrencyAmount(string currencyItemId, int amount) throw (cocos2dx_VirtualItemNotFoundException&){
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:currencyItemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:currencyItemId.c_str() length:strlen(currencyItemId.c_str()) encoding:NSUTF8StringEncoding];
return [StoreInventory addAmount:amount toCurrency:str];
}
@catch (VirtualItemNotFoundException *exception) {
@@ -33,7 +32,7 @@
int cocos2dx_StoreInventory::removeCurrencyAmount(string currencyItemId, int amount) throw (cocos2dx_VirtualItemNotFoundException&){
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:currencyItemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:currencyItemId.c_str() length:strlen(currencyItemId.c_str()) encoding:NSUTF8StringEncoding];
return [StoreInventory removeAmount:amount fromCurrency:str];
}
@catch (VirtualItemNotFoundException *exception) {
@@ -43,7 +42,7 @@
int cocos2dx_StoreInventory::getGoodBalance(string goodItemId) throw (cocos2dx_VirtualItemNotFoundException&){
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:goodItemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:goodItemId.c_str() length:strlen(goodItemId.c_str()) encoding:NSUTF8StringEncoding];
return [StoreInventory getGoodBalance:str];
}
@catch (VirtualItemNotFoundException *exception) {
@@ -53,7 +52,7 @@
int cocos2dx_StoreInventory::addGoodAmount(string goodItemId, int amount) throw (cocos2dx_VirtualItemNotFoundException&){
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:goodItemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:goodItemId.c_str() length:strlen(goodItemId.c_str()) encoding:NSUTF8StringEncoding];
return [StoreInventory addAmount:amount toGood:str];
}
@catch (VirtualItemNotFoundException *exception) {
@@ -63,7 +62,7 @@
int cocos2dx_StoreInventory::removeGoodAmount(string goodItemId, int amount) throw (cocos2dx_VirtualItemNotFoundException&){
@try {
- NSString *str = [AnalyticXStringUtil nsstringFromCString:goodItemId.c_str()];
+ NSString * str = [[NSString alloc] initWithBytes:goodItemId.c_str() length:strlen(goodItemId.c_str()) encoding:NSUTF8StringEncoding];
return [StoreInventory removeAmount:amount fromGood:str];
}
@catch (VirtualItemNotFoundException *exception) {
View
3 cocos2dx-store/ios/iOSHelper.mm
@@ -7,9 +7,8 @@
//
#include "iOSHelper.h"
-#import "AnalyticXStringUtil.h"
void iOSHelper::LogMessage(const char* msg) {
- NSString *message = [AnalyticXStringUtil nsstringFromCString:msg];
+ NSString *message = [[NSString alloc] initWithBytes:msg length:strlen(msg) encoding:NSUTF8StringEncoding];
NSLog(@"%@", message);
}
View
18 cocos2dx-store/proj.android/.idea/misc.xml
@@ -9,23 +9,5 @@
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
- <component name="SvnConfiguration" maxAnnotateRevisions="500" myUseAcceleration="nothing" myAutoUpdateAfterCommit="false" cleanupOnStartRun="false">
- <option name="USER" value="" />
- <option name="PASSWORD" value="" />
- <option name="mySSHConnectionTimeout" value="30000" />
- <option name="mySSHReadTimeout" value="30000" />
- <option name="LAST_MERGED_REVISION" />
- <option name="MERGE_DRY_RUN" value="false" />
- <option name="MERGE_DIFF_USE_ANCESTRY" value="true" />
- <option name="UPDATE_LOCK_ON_DEMAND" value="false" />
- <option name="IGNORE_SPACES_IN_MERGE" value="false" />
- <option name="DETECT_NESTED_COPIES" value="true" />
- <option name="CHECK_NESTED_FOR_QUICK_MERGE" value="false" />
- <option name="IGNORE_SPACES_IN_ANNOTATE" value="true" />
- <option name="SHOW_MERGE_SOURCES_IN_ANNOTATE" value="true" />
- <option name="FORCE_UPDATE" value="false" />
- <option name="IGNORE_EXTERNALS" value="false" />
- <myIsUseDefaultProxy>false</myIsUseDefaultProxy>
- </component>
</project>
View
2 cocos2dx-store/proj.android/.idea/vcs.xml
@@ -2,6 +2,8 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
+ <mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
+ <mapping directory="$PROJECT_DIR$/../../submodules/android-store" vcs="Git" />
</component>
</project>
View
2 cocos2dx-store/proj.android/jni/Android.mk
@@ -8,8 +8,10 @@ LOCAL_MODULE_FILENAME := libhellocpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
+ ../../Classes/JniHelpers.cpp \
../../Classes/cocos2dx_StoreController.cpp \
../../Classes/cocos2dx_StoreInventory.cpp \
+ ../../Classes/cocos2dx_StoreInfo.cpp \
../../Classes/com_soomla_store_EventHandlerBridge.cpp \
../../Classes/GameMenuItem.cpp \
../../Classes/MainScene.cpp \
View
56 cocos2dx-store/proj.android/src/com/soomla/store/StoreInfoBridge.java
@@ -0,0 +1,56 @@
+package com.soomla.store;
+
+import com.soomla.store.data.StoreInfo;
+import com.soomla.store.domain.data.VirtualCurrencyPack;
+import com.soomla.store.domain.data.VirtualGood;
+import com.soomla.store.exceptions.VirtualItemNotFoundException;
+
+public class StoreInfoBridge {
+
+ static String getPackitemId(String itemId) throws VirtualItemNotFoundException {
+ VirtualCurrencyPack pack = StoreInfo.getInstance().getPackByItemId(itemId);
+ return pack.getProductId();
+ }
+
+ static String getPackName(String itemId) throws VirtualItemNotFoundException {
+
+ VirtualCurrencyPack pack = StoreInfo.getInstance().getPackByItemId(itemId);
+
+ return pack.getName();
+ }
+
+ static String getPackDescription(String itemId) throws VirtualItemNotFoundException {
+
+ VirtualCurrencyPack pack = StoreInfo.getInstance().getPackByItemId(itemId);
+
+ return pack.getDescription();
+ }
+
+ static double getPackPrice(String itemId) throws VirtualItemNotFoundException {
+
+ VirtualCurrencyPack pack = StoreInfo.getInstance().getPackByItemId(itemId);
+
+ return pack.getPrice();
+ }
+
+ static String getGoodName(String itemId) throws VirtualItemNotFoundException {
+
+ VirtualGood good = StoreInfo.getInstance().getVirtualGoodByItemId(itemId);
+
+ return good.getName();
+ }
+
+ static String getGoodDescription(String itemId) throws VirtualItemNotFoundException {
+
+ VirtualGood good = StoreInfo.getInstance().getVirtualGoodByItemId(itemId);
+
+ return good.getDescription();
+ }
+
+ static int getGoodPriceForCurrency(String goodItemId, String currencyItemId) throws VirtualItemNotFoundException {
+
+ VirtualGood good = StoreInfo.getInstance().getVirtualGoodByItemId(goodItemId);
+
+ return good.getCurrencyValues().get(currencyItemId);
+ }
+}

0 comments on commit 438cefe

Please sign in to comment.