Exemplo n.º 1
0
GameSettings init_game_data(lua_State* L) {
	DataFiles dfiles = load_datafilenames("res/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.deinitialize(L);
	load_tileset_data(dfiles.tileset_files);

	// --- ITEM DATA ---
	lua_items = load_item_data(L, dfiles.item_files);

	lua_projectiles = load_projectile_data(L, dfiles.projectile_files,
			lua_items);
	load_projectile_item_entries();

	lua_spells = load_spell_data(L, dfiles.spell_files);

	load_weapon_data(L, dfiles.weapon_files, &lua_items);
	load_weapon_item_entries();

	load_armour_data(L, dfiles.armour_files, &lua_items);
	load_armour_item_entries();
	// --- ITEM DATA ---

	lua_effects = load_effect_data(L, dfiles.effect_files);
	lua_enemies = load_enemy_data(L, dfiles.enemy_files);

	load_itemgenlist_data(L, dfiles.itemgenlist_files);
	lua_dungeon = load_dungeon_data(L, dfiles.level_files);
	lua_dungeon.deinitialize(L);
	lua_classes = load_class_data(L, dfiles.class_files);

	GameSettings settings = load_settings_data("res/settings.yaml", L,
			&lua_settings);

	return settings;
}
Exemplo 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);
	}
}