Beispiel #1
0
static void Param(
	CONFIG & config,
	bool write,
	CONFIG::iterator & section,
	const std::string & name,
	T & value)
{
	if (write)
	{
		config.SetParam(section, name, value);
	}
	else
	{
		config.GetParam(section, name, value);
	}
}
Beispiel #2
0
void SETTINGS::Set(const std::map<std::string, std::string> & options)
{
	CONFIG tempconfig;
	for (std::map<std::string, std::string>::const_iterator i = options.begin(); i != options.end(); ++i)
	{
		std::string section;
		std::string param = i->first;
		size_t n = param.find(".");
		if (n < param.length())
		{
			section = param.substr(0, n);
			param.erase(0, n + 1);
		}
		tempconfig.SetParam(section, param, i->second);
	}
	Serialize(false, tempconfig);
}
Beispiel #3
0
void CARCONTROLMAP_LOCAL::Save(CONFIG & controls_config, std::ostream & info_output, std::ostream & error_output)
{
	int id = 0;
	for (std::map <CARINPUT::CARINPUT, std::vector <CONTROL> >::iterator n = controls.begin(); n != controls.end(); ++n)
	{
		for (std::vector <CONTROL>::iterator i = n->second.begin(); i != n->second.end(); ++i)
		{
			std::string ctrl_name = "INVALID";
			CARINPUT::CARINPUT inputid = n->first;
			for (std::map <std::string, CARINPUT::CARINPUT>::const_iterator s = carinput_stringmap.begin(); s != carinput_stringmap.end(); ++s)
			{
				if (s->second == inputid) ctrl_name = s->first;
			}

			std::stringstream ss;
			ss << "control mapping " << std::setfill('0') << std::setw(2) << id;

			CONFIG::iterator section;
			controls_config.GetSection(ss.str(), section);
			controls_config.SetParam(section, "name", ctrl_name);

			CONTROL & curctrl = *i;
			if (curctrl.type == CONTROL::JOY)
			{
				controls_config.SetParam(section, "type", "joy");
				controls_config.SetParam(section, "joy_index", curctrl.joynum);

				if (curctrl.joytype == CONTROL::JOYAXIS)
				{
					controls_config.SetParam(section, "joy_type", "axis");
					controls_config.SetParam(section, "joy_axis", curctrl.joyaxis );
					switch (curctrl.joyaxistype) {
						case CONTROL::POSITIVE:
							controls_config.SetParam(section, "joy_axis_type", "positive");
							break;
						case CONTROL::NEGATIVE:
							controls_config.SetParam(section, "joy_axis_type", "negative");
							break;
						case CONTROL::BOTH:
							controls_config.SetParam(section, "joy_axis_type", "both");
							break;
					}
					controls_config.SetParam(section, "deadzone", curctrl.deadzone);
					controls_config.SetParam(section, "exponent", curctrl.exponent);
					controls_config.SetParam(section, "gain", curctrl.gain);
				}
				else if (curctrl.joytype == CONTROL::JOYBUTTON)
				{
					controls_config.SetParam(section, "joy_type", "button");
					controls_config.SetParam(section, "joy_button", curctrl.joybutton);
					controls_config.SetParam(section, "once", curctrl.onetime);
					controls_config.SetParam(section, "down", curctrl.joypushdown);
				}
			}
			else if (curctrl.type == CONTROL::KEY)
			{
				controls_config.SetParam(section, "type", "key");
				std::string keyname = "UNKNOWN";
				for (std::map <std::string, int>::iterator k = legacy_keycodes.begin(); k != legacy_keycodes.end(); k++)
					if (k->second == curctrl.keycode)
						keyname = k->first;
				controls_config.SetParam(section, "key", keyname);
				controls_config.SetParam(section, "keycode", curctrl.keycode);
				controls_config.SetParam(section, "once", curctrl.onetime);
				controls_config.SetParam(section, "down", curctrl.keypushdown);
			}
			else if (curctrl.type == CONTROL::MOUSE)
			{
				controls_config.SetParam(section, "type", "mouse");
				if (curctrl.mousetype == CONTROL::MOUSEBUTTON)
				{
					controls_config.SetParam(section, "mouse_type", "button");
					controls_config.SetParam(section, "mouse_button", curctrl.mbutton );
					controls_config.SetParam(section, "once", curctrl.onetime );
					controls_config.SetParam(section, "down", curctrl.mouse_push_down );
				}
				else if (curctrl.mousetype == CONTROL::MOUSEMOTION)
				{
					std::string direction = "invalid";
					CONTROL::MOUSEDIRECTION mdir = curctrl.mdir;
					if ( mdir == CONTROL::UP )
					{
						direction = "up";
					}
					else if ( mdir == CONTROL::DOWN )
					{
						direction = "down";
					}
					else if ( mdir == CONTROL::LEFT )
					{
						direction = "left";
					}
					else if ( mdir == CONTROL::RIGHT )
					{
						direction = "right";
					}

					controls_config.SetParam(section, "mouse_type", "motion");
					controls_config.SetParam(section, "mouse_motion", direction);

					controls_config.SetParam(section, "deadzone", curctrl.deadzone);
					controls_config.SetParam(section, "exponent", curctrl.exponent);
					controls_config.SetParam(section, "gain", curctrl.gain);
				}
			}

			id++;
		}
	}
}
void CARCONTROLMAP_LOCAL::Save(CONFIG & controls_config)
{
	int id = 0;
	for (size_t n = 0; n < controls.size(); ++n)
	{
		std::string ctrl_name = GetStringFromInput(CARINPUT::CARINPUT(n));
		if (ctrl_name.empty())
			continue;

		for (size_t i = 0; i < controls[n].size(); ++i)
		{
			std::stringstream ss;
			ss << "control mapping " << std::setfill('0') << std::setw(2) << id;

			CONFIG::iterator section;
			controls_config.GetSection(ss.str(), section);
			controls_config.SetParam(section, "name", ctrl_name);

			CONTROL & curctrl = controls[n][i];
			if (curctrl.type == CONTROL::JOY)
			{
				controls_config.SetParam(section, "type", "joy");
				controls_config.SetParam(section, "joy_index", curctrl.joynum);

				if (curctrl.joytype == CONTROL::JOYAXIS)
				{
					controls_config.SetParam(section, "joy_type", "axis");
					controls_config.SetParam(section, "joy_axis", curctrl.joyaxis );
					switch (curctrl.joyaxistype) {
						case CONTROL::POSITIVE:
							controls_config.SetParam(section, "joy_axis_type", "positive");
							break;
						case CONTROL::NEGATIVE:
							controls_config.SetParam(section, "joy_axis_type", "negative");
							break;
					}
					controls_config.SetParam(section, "deadzone", curctrl.deadzone);
					controls_config.SetParam(section, "exponent", curctrl.exponent);
					controls_config.SetParam(section, "gain", curctrl.gain);
				}
				else if (curctrl.joytype == CONTROL::JOYBUTTON)
				{
					controls_config.SetParam(section, "joy_type", "button");
					controls_config.SetParam(section, "joy_button", curctrl.keycode);
					controls_config.SetParam(section, "once", curctrl.onetime);
					controls_config.SetParam(section, "down", curctrl.pushdown);
				}
			}
			else if (curctrl.type == CONTROL::KEY)
			{
				controls_config.SetParam(section, "type", "key");
				std::string keyname = GetStringFromKeycode(curctrl.keycode);
				controls_config.SetParam(section, "key", keyname);
				controls_config.SetParam(section, "keycode", curctrl.keycode);
				controls_config.SetParam(section, "once", curctrl.onetime);
				controls_config.SetParam(section, "down", curctrl.pushdown);
			}
			else if (curctrl.type == CONTROL::MOUSE)
			{
				controls_config.SetParam(section, "type", "mouse");
				if (curctrl.mousetype == CONTROL::MOUSEBUTTON)
				{
					controls_config.SetParam(section, "mouse_type", "button");
					controls_config.SetParam(section, "mouse_button", curctrl.keycode );
					controls_config.SetParam(section, "once", curctrl.onetime );
					controls_config.SetParam(section, "down", curctrl.pushdown );
				}
				else if (curctrl.mousetype == CONTROL::MOUSEMOTION)
				{
					std::string direction = "invalid";
					CONTROL::MOUSEDIRECTION mdir = curctrl.mdir;
					if ( mdir == CONTROL::UP )
					{
						direction = "up";
					}
					else if ( mdir == CONTROL::DOWN )
					{
						direction = "down";
					}
					else if ( mdir == CONTROL::LEFT )
					{
						direction = "left";
					}
					else if ( mdir == CONTROL::RIGHT )
					{
						direction = "right";
					}

					controls_config.SetParam(section, "mouse_type", "motion");
					controls_config.SetParam(section, "mouse_motion", direction);

					controls_config.SetParam(section, "deadzone", curctrl.deadzone);
					controls_config.SetParam(section, "exponent", curctrl.exponent);
					controls_config.SetParam(section, "gain", curctrl.gain);
				}
			}

			id++;
		}
	}
}