Esempio n. 1
0
void init_lua_data(GameState* gs, lua_State* L) {
	//Lua configuration
	lua_lanarts_api(gs, L);

	register_as_global(L, lua_enemies, "enemies");
	register_as_global(L, lua_effects, "effects");
//	register_as_global(L, weapons, "weapons");
	register_as_global(L, lua_items, "items");
	register_as_global(L, lua_projectiles, "projectiles");
	register_as_global(L, lua_spells, "spells");
//	register_as_global(L, sprites, "sprites");
//	register_as_global(L, dungeon, "dungeon");
	register_as_global(L, lua_classes, "classes");
	register_as_global(L, lua_settings, "settings");

	luaL_dofile(L, "res/main.lua");

	__lua_init(L, game_enemy_data);
	__lua_init(L, game_effect_data);
	__lua_init(L, game_projectile_data);
	__lua_init(L, game_item_data);
	__lua_init(L, game_spell_data);
	__lua_init(L, game_weapon_data);

//	lua_getglobal(L, "level_tests");
//	lua_call(L, 0, 0);
}
Esempio n. 2
0
void init_game_data(GameSettings& settings, lua_State* L) {
	LuaSpecialValue globals = luawrap::globals(L);

	DataFiles dfiles = load_datafilenames("game/lanarts/datafiles.yaml");

//NB: Do not re-order the way resources are loaded unless you know what you're doing!
//For example, all item data types must be loaded before room generation data

	load_tile_data(dfiles.tile_files);
	lua_sprites = load_sprite_data(L, dfiles.sprite_files);
	lua_sprites.clear();
	load_tileset_data(dfiles.tileset_files);

	update_loading_screen(L, 0, "Loading Items");
	// --- ITEM DATA ---
	// TODO: Go to new system
	lua_items = load_item_data(L, FilenameList());
	update_loading_screen(L, 10, "Loading Projectiles");

	lua_projectiles = load_projectile_data(L, dfiles.projectile_files,
			lua_items);
	update_loading_screen(L, 20, "Loading Spells");

	lua_spells = load_spell_data(L, dfiles.spell_files);
	update_loading_screen(L, 30, "Loading Weapons");

	load_weapon_data(L, dfiles.weapon_files, &lua_items);
	update_loading_screen(L, 40, "Loading Equipment");

	load_equipment_data(L, dfiles.equipment_files, &lua_items);
	update_loading_screen(L, 50, "Loading Enemies");
	// --- ITEM DATA ---

	lua_effects = load_effect_data(L, dfiles.effect_files);
	lua_enemies = load_enemy_data(L, dfiles.enemy_files);
	update_loading_screen(L, 60, "Loading Item Generation Templates");

	update_loading_screen(L, 90, "Loading Classes");
	lua_classes = load_class_data(L, FilenameList());
	update_loading_screen(L, 100, "Complete!");

	// TODO clean this up

	globals["enemies"] = lua_enemies;
	globals["effects"] = lua_effects;
	globals["items"] = lua_items;
	globals["projectiles"] = lua_projectiles;
	LuaValue weapons = luawrap::ensure_table(globals["weapons"]);
	int ind = 0;
	for (int i = 0; i < game_item_data.size(); i++) {
		ItemEntry& ientry = get_item_entry(i);
		if (dynamic_cast<WeaponEntry*>(&ientry)) {
			WeaponEntry& entry = get_weapon_entry(i);

			weapons[++ind] = lua_items[entry.name];
		}
	}
	LuaValue armour = luawrap::ensure_table(globals["armour"]);
	ind = 0;
	for (int i = 0; i < game_item_data.size(); i++) {
		ItemEntry& ientry = get_item_entry(i);
		if (dynamic_cast<EquipmentEntry*>(&ientry)) {
			if (dynamic_cast<WeaponEntry*>(&ientry) || dynamic_cast<ProjectileEntry*>(&ientry)) {
				continue;
			}
			ItemEntry& entry = get_item_entry(i);

			armour[++ind] = lua_items[entry.name];
		}
	}
	LuaValue consumables = luawrap::ensure_table(globals["consumable"]);
	for (int i = 0; i < game_item_data.size(); i++) {
		ItemEntry& ientry = get_item_entry(i);
		if (!dynamic_cast<EquipmentEntry*>(&ientry)) {
			ItemEntry& entry = get_item_entry(i);

			consumables[entry.name] = lua_items[entry.name];
		}
	}
	globals["spells"] = lua_spells;
	globals["classes"] = lua_classes;

	__lua_init(L, game_enemy_data);
	__lua_init(L, game_effect_data);

	for (int i = 0; i < game_item_data.size(); i++) {
		game_item_data[i]->initialize(L);
	}

	for (int i = 0; i < game_spell_data.size(); i++) {
		game_spell_data[i].initialize(L);
	}
}