// partial particles.bin loader

var physx_type_preset = reader.ReadSection("physx_type_preset");
var physx_type_preset_names = ["Light Gases", "Rigid Bodies", "Liquids", "Heavy Gases"];

while(physx_type_preset_names.length)
{
	var preset = physx_type_preset.ReadSection(physx_type_preset_names.shift());
	
	preset.ReadBool("self_collided");
	preset.ReadFP32("damping");
	preset.ReadFP32("friction");
	preset.ReadFP32("restitution");
	preset.ReadBool("apply_physx_gravity");
	preset.ReadBool("correct_moving");
	preset.ReadFP32("stiffness");
	preset.ReadFP32("viscosity");
	preset.ReadFP32("density");
}

var effects = reader.ReadArray("effects");
for(var i = 0; effects.More(); i++)
{
	var effect = effects.ReadSection(RecStr("rec_", i, 4), false);
	
	effect.ReadString("name");
	effect.ReadU16("version");
	effect.ReadFP32("time_limit");
	effect.ReadU16("max_particles");
	effect.ReadFP32("particles_life_time");
	effect.ReadBool("fl_physx_enabled");
	effect.ReadBool("fl_physx_anim_enabled");
	effect.ReadU8("physx_type");
	effect.ReadBool("fl_sort");
	effect.ReadBool("fl_velocity_scale");
	effect.ReadBool("fl_align_to_motion");
	effect.ReadBool("fl_face_align");
	effect.ReadBool("fl_framed");
	effect.ReadBool("fl_animated");
	effect.ReadBool("fl_random_frame");
	effect.ReadBool("fl_random_playback");
	effect.ReadHintStr("texture_name", "texture, str_shared");
	effect.ReadHintStr("shader_name", "shader, str_shared");
	effect.ReadVec2("frame_size");
	effect.ReadU16("frame_wcount_p2");
	effect.ReadU16("frame_count");
	effect.ReadHint("frame_num", "tex_frame, u_vector<u16>");
	
	// Replace ME (u16_array)
	{
		var count = effect.ReadU32("frame_num_count");
		for(var j = 0; j < count; j++)
			effect.ReadU16("frame_num_"+j);
	}
		
	effect.ReadFP32("frame_speed");
	effect.ReadVec3("velocity_scale");
	effect.ReadVec3("still_rotation", "ang3f");
	effect.ReadFP32("motion_factor");
	
	var acount = effect.ReadU16("action_count");
	for(var k = 0; k < acount; k++)
	{
		var action = effect.ReadSection(RecStr("action_", k, 4));
		
		var atype = action.ReadU16("type");
		action.ReadBool("enabled");
		action.ReadString("description");
		
		switch(atype)
		{
			case 22: // Source
			action.ReadFP32("particle_rate");
			action.ReadFP32("mass");
			action.ReadFP32("age");
			action.ReadFP32("age_sigma");
			var s = action.ReadSection("position_dom");
			var s = action.ReadSection("color_cdom");
			var s = action.ReadSection("color_adom");
			var s = action.ReadSection("size_dom");
			var s = action.ReadSection("rot_velocity_dom");
			var s = action.ReadSection("rotation_dom");
			var s = action.ReadSection("velocity_dom");
			action.ReadBool("dbg_draw");
			break;
		}
	}
}

var modifs = reader.ReadArray("modifs");
for(var i = 0; modifs.More(); i++)
{
	var modif = modifs.ReadSection(RecStr("rec_", i, 4), false);
	modif.ReadString("name");
}

var systems = reader.ReadArray("systems");
for(var i = 0; systems.More(); i++)
{
	var system = systems.ReadSection(RecStr("rec_", i, 4), false);
	
	system.ReadString("name");
	system.ReadFP32("time_limit");
	system.ReadHint("flags", "flags32");
	system.ReadU32("flags");
	system.ReadVec3("force_aabb_mn");
	system.ReadVec3("force_aabb_mx");
	system.ReadHintStr("physx_alias", "choose");
	
	var items = system.ReadArray("items");
	for(var j = 0; items.More(); j++)
	{
		var item = items.ReadSection(RecStr("item_", j, 4), false);
		
		item.ReadHintStr("main_effect_name", "particles_effect, str_shared");
		item.ReadFP32("timetable_1");
		item.ReadFP32("timetable_2");
		item.ReadHintStr("on_playing_effect_name", "particles_effect, str_shared");
		item.ReadHintStr("on_birth_effect_name", "particles_effect, str_shared");
		item.ReadHintStr("on_death_effect_name", "particles_effect, str_shared");
		item.ReadHintStr("on_kill_effect_name", "particles_effect, str_shared");
		item.ReadHint("flags", "flags32");
		item.ReadU32("flags");
	}
}