engine_test_xc.mm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // eninge_test_xc.mm
  3. // pokemon_test_xc
  4. //
  5. // Created by Sam Jaffe on 12/22/18.
  6. // Copyright © 2018 Sam Jaffe. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #include <string>
  10. @interface engine_test_xc : NSObject
  11. -(NSString*) getResourceDir;
  12. @end
  13. @implementation engine_test_xc
  14. -(NSString*) getResourceDir {
  15. NSBundle* bundle = [NSBundle bundleForClass:[self class]];
  16. NSDictionary* infoDict = [bundle infoDictionary];
  17. return [infoDict objectForKey:@"Resource Directory"];
  18. }
  19. @end
  20. std::string resource_dir() {
  21. engine_test_xc * test = [[engine_test_xc alloc] init];
  22. return [[test getResourceDir] UTF8String];
  23. }
  24. std::string resource(std::string const & rel_path) {
  25. return resource_dir() + "/" + rel_path;
  26. }
  27. #include "../test/stub_config.h"
  28. #include <json/json.h>
  29. Json::Value construct_test_config(std::string const & dir = "") {
  30. Json::Value json;
  31. json["resource_path"] = dir.empty() ? resource_dir() : resource(dir);
  32. json["properties"]["object"] = "@resource/object";
  33. return json;
  34. }
  35. Config Config::from_dir(std::string const & dir) {
  36. return Config(construct_test_config(dir));
  37. }
  38. Config::Config() : engine::env::Config(construct_test_config()) {}
  39. Config::Config(std::string const & filename) :
  40. engine::env::Config(Config().resource(filename)) {}
  41. Config::Config(Json::Value const & properties) :
  42. engine::env::Config(properties) {}