예제 #1
0
파일: game.c 프로젝트: IGLOU-EU/yirl
int ygInit(GameConfig *cfg)
{
  static int t;

  /* Init parseurs */
  CHECK_AND_RET(t = ydJsonInit(), -1, -1,
		    "json init failed");
  CHECK_AND_RET(jsonManager = ydNewManager(t), NULL, -1,
		    "json init failed");
  parsers[t] = jsonManager;

  /* Init scripting */
  /* TODO init internal lua function */
  CHECK_AND_RET(t = ysLuaInit(), -1, -1, "lua init failed");
  CHECK_AND_RET(luaManager = ysNewManager(NULL, t), NULL, -1,
		    "lua init failed");

  CHECK_AND_RET(yesLuaRegister(luaManager), -1, -1, "lua init failed");

  /* Init widgets */
  CHECK_AND_RET(ywidInitCallback(), -1, -1, "can not init callback");
  CHECK_AND_RET(ywinAddCallback(ywinCreateNativeCallback("FinishGame",
							 ygTerminateCallback)),
		-1, -1, "can not add game's callback");
  CHECK_AND_RET(ywMenuInit(), -1, -1, "Menu init failed");
  CHECK_AND_RET(ywMapInit(), -1, -1, "Map init failed");
  CHECK_AND_RET(ywTextScreenInit(), -1, -1, "Text Screen init failed");
  CHECK_AND_RET(ywContenerInit(), -1, -1, "Contener init failed");

  /* Init sound */
  sound_init(LIB_VLC);

  for (GList *tmp = cfg->rConf; tmp; tmp = tmp->next) {
    //TODO check which render to use :)
    if (yuiStrEqual(TO_RC(tmp->data)->name, "curses")) {
#ifdef WITH_CURSES
      ycursInit();
      CHECK_AND_RET(ycursRegistreMenu(), -1, -1, "Menu init failed");
      CHECK_AND_RET(ycursRegistreTextScreen(), -1, -1,
			"Text Screen init failed");
      CHECK_AND_RET(ycursRegistreMap(), -1, -1, "Map init failed");
#else
      /* print error */
#endif
    } else if (yuiStrEqual(TO_RC(tmp->data)->name, "sdl2")) {
#ifdef WITH_SDL
      ysdl2Init();
      CHECK_AND_RET(ysdl2RegistreTextScreen(), -1, -1,
			"Text Screen init failed");
      CHECK_AND_RET(ysdl2RegistreMenu(), -1, -1, "Menu init failed");
      CHECK_AND_RET(ysdl2RegistreMap(), -1, -1, "Map init failed");
#else
      /* print error */
#endif
    }
  }
  init = 1;
  return 0;
}
예제 #2
0
파일: menu.c 프로젝트: cosmo-ray/yirl
void testPanelMenuSdl2(void)
{
  yeInitMem();
  int t = ydJsonInit();
  void *jsonManager;
  Entity *oret, *ret;
  YWidgetState *wid;

  ysRegistreFunc(ysNativeManager(), "menuTest", testMenuEnter);

  /* load files */
  g_assert(t != -1);
  g_assert(ydJsonGetType() == t);
  jsonManager = ydNewManager(t);
  g_assert(jsonManager != NULL);
  oret = ydFromFile(jsonManager, TESTS_PATH"/widget.json", NULL);
  ret = yeGet(oret, "MenuTest");
  g_assert(ret);
  g_assert(!ydJsonEnd());
  g_assert(!ydDestroyManager(jsonManager));

  t = ywMenuInit();
  g_assert(t == 0);

  g_assert(ysdl2Init() != -1);
  g_assert(ysdl2Type() == 0);

  yeCreateString("panel", ret, "mn-type");
  g_assert(ysdl2RegistreMenu() == 0);

  wid = ywidNewWidget(ret, NULL);
  g_assert(wid);

  do {
    g_assert(ywidRend(wid) != -1);
  } while(ywidDoTurn(wid) != ACTION);

  g_assert(!ywMenuEnd());
  YWidDestroy(wid);
  ysdl2Destroy();
  /* end libs */
  YE_DESTROY(oret);
  yeEnd();
}