shared_ptr<osb::Event> ParseEvent(vector<GString> split)
{
	auto ks = split[0];
	shared_ptr<osb::Event> evt;
	boost::algorithm::to_upper(ks);

	if (ks == "V"){
		auto xvt = make_shared<osb::VectorScaleEvent>();
		// xvt->SetValue()
		evt = xvt;
	}
	if (ks == "S") {
	}
	if (ks == "M") {
	}
	if (ks == "MX") {
	}
	if (ks == "MY") {
	}
	if (ks == "C") {
	}
	if (ks == "P") {
	}
	if (ks == "F") {
	}
	if (ks == "L") {
	}

	evt->SetTime(latof(split[2]));
	evt->SetEndTime(latof(split[3]));

	return evt;
}
bool ScreenGameplay7K::BindKeysToLanes(bool UseTurntable)
{
    std::string KeyProfile;
    std::string value;
    std::vector<std::string> res;

    if (UseTurntable)
        KeyProfile = Configuration::GetConfigs("KeyProfileSpecial" + Utility::IntToStr(CurrentDiff->Channels));
    else
        KeyProfile = Configuration::GetConfigs("KeyProfile" + Utility::IntToStr(CurrentDiff->Channels));

    value = Configuration::GetConfigs("Keys", KeyProfile);
    res = Utility::TokenSplit(value);

    for (unsigned i = 0; i < CurrentDiff->Channels; i++)
    {
        lastClosest[i] = 0;

        if (i < res.size())
            GearBindings[static_cast<int>(latof(res[i]))] = i;
        else
        {
            if (!Auto)
            {
                Log::Printf("Mising bindings starting from lane " + Utility::IntToStr(i) + " using profile " + KeyProfile);
                return false;
            }
        }

        HeldKey[i] = false;
        GearIsPressed[i] = 0;
    }

    return true;
}
shared_ptr<osb::SpriteList> ReadOSBEvents(std::istream& event_str)
{
	auto list = make_shared<osb::SpriteList>();
	int previous_lead = 100;
	shared_ptr<osb::BGASprite> sprite = nullptr;
	shared_ptr<osb::Loop> loop = nullptr;
	bool readingLoop = false;

	GString line;
	while (std::getline(event_str, line))
	{
		int lead_spaces;
		line = line.substr(line.find("//")); // strip comments
		lead_spaces = line.find_first_not_of("\t _");
		line = line.substr(lead_spaces, line.length() - lead_spaces + 1);

		vector<GString> split_result;
		boost::split(split_result, line, boost::is_any_of(","));
		for (auto &&s : split_result) boost::algorithm::to_lower(s);

		if (!line.length() || !split_result.size()) continue;

		if (lead_spaces < previous_lead && !readingLoop)
		{
			if (split_result[0] == "sprite")
			{
				Vec2 new_position(latof(split_result[3]), latof(split_result[4]));
				sprite = make_shared<osb::BGASprite>(split_result[1], OriginFromString(split_result[2]), new_position);
				list->push_back(sprite);
			}
		} else {
			if (!sprite)
				throw std::runtime_error("OSB command unpaired with sprite.");

			// If it's a loop, check if we're out of it.
			// If we're out of it, read a regular event, otherwise, read an event to the loop
			if (readingLoop)
			{
				if (lead_spaces < previous_lead) {
					readingLoop = false;

					// We're done reading the loop - unroll it.
					auto loop_events = loop->Unroll();
					for (auto i = 0; i < osb::EVT_COUNT; i++)
						for (auto evt : (*loop_events)[i])
							sprite->AddEvent(evt);
				}
				else
					loop->AddEvent(ParseEvent(split_result));
			}
			
			// It's not a command on the loop, or we weren't reading a loop in the first place.
			// Read a regular command.

			// Not "else" because we do want to execute this if we're no longer reading the loop.
			if (!readingLoop) {
				auto ev = ParseEvent(split_result);

				// A loop began - set that we are reading a loop and set this loop as where to add the following commands.
				if (ev->GetEventType() == osb::EVT_LOOP)
				{
					loop = static_pointer_cast<osb::Loop>(ev);
					readingLoop = true;
				}else // add this event, if not a loop to this sprite. It'll be unrolled once outside.
					sprite->AddEvent(ev);
			}
		}

		previous_lead = lead_spaces;
	}

	return list;
}
Beispiel #4
0
void BindingsManager::Initialize()
{
	SpecialKeys.clear();
	for (int i = 0; i < NUM_OF_STATIC_SPECIAL_KEYS; i++)
		SpecialKeys.push_back(StaticSpecialKeys[i]);


	//controllerToUse = 1; should use this if the user entered garbage data (anything that isn't a number)
	controllerToUse = (int)Configuration::GetConfigf("ControllerNumber") - 1;

	if (glfwJoystickPresent(controllerToUse))
	{
		int numOfButtons;
		glfwGetJoystickButtons(controllerToUse, &numOfButtons);
		if (numOfButtons) {
			for (int i = 1; i <= numOfButtons; i++) {
				char name[32];
				sprintf(name, "Controller%d", i);
				sk_s thisButton;
				strcpy(thisButton.KeyString, name);
				thisButton.boundkey = 1000 + i;
				SpecialKeys.push_back(thisButton);
			}
		}
	}

	JoystickEnabled = (glfwJoystickPresent(GLFW_JOYSTICK_1) == GL_TRUE);

	
	std::map <GString, GString> fields;
	Configuration::GetConfigListS("SystemKeys", fields, "");

	// key = function
	// e.g. Z = gameclick, X = gameclick
	for (auto i = fields.begin(); i != fields.end(); i++)
	{
		// transform special name into keytype index
		int idx = getIndexForKeytype(i->second.c_str());

		// ah it's valid
		if (idx != -1)
		{
			// get the key in either int or name or char format and save that into the key -> command translator
			int Key = KeyTranslate(i->first.c_str());

			if (Key) // a valid key, probably
				ScanFunction[Key] = (KeyType)idx;
		}
	}
	
	// fill missing default keys after it's done
	for (int i = 0; i < DEFAULT_KEYS_COUNT; i++)
	{
		if (ScanFunction.find(defaultKeys[i].key) == ScanFunction.end())
		{
			// fill the key -> command translation
			ScanFunction[defaultKeys[i].key] = defaultKeys[i].command;

			// write it out to the config file
			GString charOut;
			if (defaultKeys[i].key <= 255 && isgraph(defaultKeys[i].key)) // we're not setting like, gibberish
			{
				charOut = Utility::CharToStr(defaultKeys[i].key);
			}
			else
			{
				charOut = getNameForUntranslatedKey(defaultKeys[i].key);
			}

			Configuration::SetConfig(charOut, getNameForKeytype(defaultKeys[i].command), "SystemKeys");
		}
	}

	int i = 1;
	std::map<GString, GString> Keys;
	Configuration::GetConfigListS("Keys7K", Keys, "");

	for (auto v : Keys)
	{
		int Binding = KeyTranslate(v.first);
		if (Binding)
			ScanFunction7K[Binding] = floor(latof(v.second));
	}
}