Example #1
0
/**
*  @brief
*    Test: GetChar() functionality
*/
void Application30::TestGetChar(const String &sDevice)
{
	// Start
	System::GetInstance()->GetConsole().Print("Testing GetChar() with device '" + sDevice + "'\n");

	// Get device
	Device *pDevice = InputManager::GetInstance()->GetDevice(sDevice);
	if (pDevice) {
		String sInput;

		// Main loop
		m_bExit = false;
		while (!m_bExit) {
			// Ping the frontend
			GetFrontend().Ping();

			// Update devices
			InputManager::GetInstance()->Update();

			// Get character
			char nChar = pDevice->GetChar();
			if (nChar != '\0') {
				// Escape
				if (nChar == 0x1B) {
					// Exit
					m_bExit = true;

				// Enter
				} else if (nChar == 0x0D) {
					// Next word
					System::GetInstance()->GetConsole().Print('\n');
					sInput = "";

				// Backspace
				} else if (nChar == 0x08) {
					// Delete last character
					sInput = sInput.GetSubstring(0, sInput.GetLength()-1);

					// Print on next line
					System::GetInstance()->GetConsole().Print('\n');
					System::GetInstance()->GetConsole().Print(sInput);

				// Character
				} else if ((nChar >= '0' && nChar <= '9') || (nChar >= 'a' && nChar <= 'z') ||
							nChar == '+' || nChar == '-' || nChar == '*' || nChar == '/' || nChar == ',' || nChar == '.' ||
							nChar == 0x20) {
					// Add char to string
					sInput += nChar;

					// Print char
					System::GetInstance()->GetConsole().Print(String() + nChar);
				}
			}

			// Wait 10 milliseconds
			System::GetInstance()->Sleep(10);
		}
	} else {
		// Error
		System::GetInstance()->GetConsole().Print("ERROR: Could not get device\n");
	}
}
Example #2
0
String FillRight(const String& text, int n)
{
	int q = n - text.GetLength();
	return q > 0 ? text + String(' ', q) : text;
}
Example #3
0
String HelpTopicSave(Vector<String>& saved_files, String text_folder, HelpTopicInfoMap& diff, String out_folder, bool skip_file_write)
{
	Vector<String> drls = HelpTopicListTextFolder(IsNull(out_folder) ? text_folder : String::GetVoid());
	Index<String> used_names;
	HelpTopicInfoMap& map = HelpTopicMap();
	String out;
	bool first = true;
	String dir_dph;
	for(int t = 0; t < drls.GetCount(); t++) {
		String drl = drls[t];
		const HelpTopicInfo& topicinfo = HelpTopicGet(drl);
		String space, nesting, topic;
		HelpParseDPP(drl, space, nesting, topic);
		String outdir = AppendFileName(Nvl(out_folder, text_folder), "doc.dpp");
		String title = HelpTopicTextModuleTitle(space, nesting, topic, used_names);
		for(int l = 0; l < topicinfo.language.GetCount(); l++)
			if(!IsNull(topicinfo.title[l]) || !IsNull(topicinfo.text[l])) {
				String file;
				file << title << '_' << LNGAsTextShort(topicinfo.language[l]) << ".dpx";
				String path = AppendFileName(outdir, file);
				dir_dph << "#include \"" << path << "\"\n";
				if(!skip_file_write) {
					String lng = LNGAsText(topicinfo.language[l]);
					String out;
					out << "HELP_TOPIC(" << AsCString(space)
						<< ", " << AsCString(nesting)
						<< ", " << AsCString(topic)
						<< ", " << AsCString(lng)
						<< ", " << AsCString(topicinfo.title[l]) << ")\n";
					String text = topicinfo.text[l];
					String ctext;
					const char *p = text;
					while(*p) {
						const char *b = p;
						enum { CHUNK = 100 };
						while(*p && *p++ != '\n' && p - b < CHUNK)
							;
						if(!IsNull(ctext))
							ctext << "\n\t";
						ctext << AsCString(String(b, p));
						if(ctext.GetLength() >= 5000)
						{
							out << "HELP_TEXT(\n\t" << ctext << ")\n";
							ctext = Null;
						}
					}
					if(!IsNull(ctext))
						out << "\tHELP_TEXT(\n\t" << ctext << ")\n";
					out << "HELP_END\n";
					if(first) {
						first = false;
						RealizePath(path);
					}
					if(!IsSameTextFile(LoadFile(path), out)) {
						if(!SaveFileBackup(path, out))
							throw Exc(NFormat("Nelze uložit soubor '%s'.", path));
						saved_files.Add(path);
					}
				}
				diff.GetAdd(drl) <<= topicinfo;
			}
	}
	return dir_dph;
}
Example #4
0
_JATTA_EXPORT Jatta::JSON::Array Jatta::JSON::ParseArray(Jatta::String str)
{
    Array ret;

    String value;
    bool insideString = false;
    int objInd = 0, arrayInd = 0;
    for (UInt32 i = 0; i < str.GetLength(); i++)
    {
        if (insideString)
        {
            if (str[i] == Grammar::Structural::STRING_DELIMITOR)
            {
                value += str[i];
                insideString = false;
            }
            else
            {
                value += str[i];
            }
        }
        else if (objInd > 0 || str[i] == Grammar::Structural::BEGIN_OBJECT)
        {
            if (str[i] == Grammar::Structural::END_OBJECT)
            {
                objInd--;
            }
            if (str[i] == Grammar::Structural::BEGIN_OBJECT)
            {
                objInd++;
            }
            value += str[i];
        }
        else if (arrayInd > 0 || str[i] == Grammar::Structural::BEGIN_ARRAY)
        {
            if (str[i] == Grammar::Structural::END_ARRAY)
            {
                arrayInd--;
            }
            if (str[i] == Grammar::Structural::BEGIN_ARRAY)
            {
                arrayInd++;
            }
            value += str[i];
        }
        else if (str[i] == Grammar::Structural::STRING_DELIMITOR)
        {
            value += str[i];
            insideString = true;
        }
        else if (str[i] == Grammar::Structural::VALUE_SEPERATOR)
        {
            ret.PushBack(Jatta::JSON::ParseValue(value));
            value.Set("");
        }
        else
        {
            value += str[i];
        }
    }

    if (value.GetLength() > 0)
    {
        ret.PushBack(Jatta::JSON::ParseValue(value));
    }

    return ret;
}
Example #5
0
_JATTA_EXPORT Jatta::JSON::Value Jatta::JSON::ParseString(String str)
{
    Jatta::String ret;

    UInt32 i = 0;
    if (str[0] == Grammar::Structural::STRING_DELIMITOR)
    {
        i++;
    }

    for (i; i < str.GetLength(); i++)
    {
        if (str[i] == Grammar::Structural::STRING_DELIMITOR)
        {
            break;
        }
        if (str[i] == Grammar::Strings::Escape::BEGIN_ESCAPE)
        {
            if (i+1 >= str.GetLength())
            {
                //ERROR
            }
            switch (str[i+1])
            {
                case Grammar::Strings::Escape::QUOTATION_MARK:
                {
                    ret += Grammar::Strings::QUOTATION_MARK;
                    break;
                }
                case Grammar::Strings::Escape::REVERSE_SOLIDUS:
                {
                    ret += Grammar::Strings::REVERSE_SOLIDUS;
                    break;
                }
                case Grammar::Strings::Escape::SOLIDUS:
                {
                    ret += Grammar::Strings::SOLIDUS;
                    break;
                }
                case Grammar::Strings::Escape::BACKSPACE:
                {
                    ret += Grammar::Strings::BACKSPACE;
                    break;
                }
                case Grammar::Strings::Escape::FORM_FEED:
                {
                    ret += Grammar::Strings::FORM_FEED;
                    break;
                }
                case Grammar::Strings::Escape::LINE_FEED:
                {
                    ret += Grammar::Strings::LINE_FEED;
                    break;
                }
                case Grammar::Strings::Escape::CARRIAGE_RETURN:
                {
                    ret += Grammar::Strings::CARRIAGE_RETURN;
                    break;
                }
                case Grammar::Strings::Escape::TAB:
                {
                    ret += Grammar::Strings::TAB;
                    break;
                }
                case Grammar::Strings::Escape::BEGIN_UNICODE:
                {
                    Jatta::String copy = str;
                    copy.ToLower();
                    if (i + 5 >= str.GetLength()) //Need 4 hexadecimal digits
                    {
                        //ERROR
                    }

                    UInt32 charCode = 0;
                    UInt32 place = 1;
                    for (SInt32 j = i + 4; j >= i + 1; j--)
                    {
                        if (copy[j] >= '0' && copy[j] <= '9')
                        {
                            charCode += (copy[j]-'0')*place;
                            place *= 16;
                        }
                        else if (copy[j] >= 'a' || copy[j] <= 'f' )
                        {
                            charCode += (copy[j] - 'a' + 10) * place;
                            place *= 16;
                        }
                        else
                        {
                            //ERROR! Unknown character.
                        }
                    }
                    i += 4;

                    ret += String::FromCodePoint(charCode);
                }
                break;
            }
            i += 1;
        }
        else
        {
            ret += str[i];
        }
    }

    return JSON::Value(ret);
}
Example #6
0
_JATTA_EXPORT Jatta::JSON::Value Jatta::JSON::ParseNumber(String str)
{
    bool negate = (str[0] == JSON::Grammar::Numbers::MINUS);

    UInt32 splitLoc = 0;
    UInt32 expLoc = 0;
    bool isInt = true;
    bool hasExp = false;
    for (UInt32 i = 1; i < str.GetLength(); i++)
    {
        if (str[i] == Grammar::Numbers::DECIMAL_POINT)
        {
            if (!isInt)
            {
                break;    //ERROR
            }
            isInt = false;
            splitLoc = i;
        }
        else if (str[i] == Grammar::Numbers::LOWER_EXP ||
                 str[i] == Grammar::Numbers::UPPER_EXP)
        {
            hasExp = true;
            expLoc = i;
            break;
        }
    }
    if (!hasExp)
    {
        expLoc = str.GetLength();
    }

    if (isInt)
    {
        splitLoc = expLoc;
    }

    float number = 0;
    float place = 1;

    // Start with the left side (> 0)
    for (SInt32 i = splitLoc - 1; i >= 0; i--)
    {
        if (str[i] == JSON::Grammar::Numbers::MINUS && i == 0)
        {
            break;
        }
        if (str[i] >= '0' && str[i] <= '9')
        {
            //Can't have a trail of zeros at start (unless it's the only 0)
            if (str[i] == '0' || i == splitLoc - 1)
            {
                bool bad = true;
                for (UInt32 j = 0; j < i; j++) //Check to see if there is only zeros before this.
                {
                    if (str[j] >= '1' && str[j] <= '9')
                    {
                        bad = false;
                        break;
                    }
                }
                if (bad)
                    break;
            }

            //Appears to be fine, lets add this number and increment the place.
            number += (str[i] - '0') * place;
            place *= 10;
        }
        else
        {
            //ERROR unknown Char
        }
    }

    if (!isInt) //It's a decimal!
    {
        place = 0.1;
        for (UInt32 i = splitLoc + 1; i < str.GetLength() && i < expLoc; i++)
        {
            if (str[i] >= '0' && str[i] <= '9')
            {
                number += (str[i] - '0')*place;
                place /= 10;
            }
            else
            {
                 //ERROR unknown Char
            }
        }
    }

    //Is it in scientific notation?
    if (hasExp)
    {
        float notationAmount = 0;
        bool negativeNotate = true;
        place = 1;
        for (SInt32 i = str.GetLength() - 1; i >= 0 && i > expLoc; i--)
        {
            if (str[i] >= '0' && str[i] <= '9')
            {
                notationAmount += (str[i] - '0') * place;
                place *= 10;
            }
            else if (i == expLoc+1 && str[i] == Grammar::Numbers::MINUS || str[i] == Grammar::Numbers::PLUS)
            {
                negativeNotate = (str[i] == Grammar::Numbers::MINUS);
            }
            else
            {
                //ERROR unknown Char
            }
        }
        place = 1;
        for (UInt32 i = 0; i < notationAmount; i++)
        {
            place *= 10;
        }

        if (negativeNotate)
        {
            place = 0.1;
            for (UInt32 i = 0; i < notationAmount - 1; i++)
            {
                place /= 10;
            }
        }

        number *= place;
    }

    if (negate)
    {
        number *= -1;
    }

    if ((SInt32)number == number && isInt)
    {
        return JSON::Value((SInt32)(number));
    }
    else
    {
        return JSON::Value(number);
    }
}
void WillowGame::DrawHUD()
{
	// Time

	int minutes = (int) m_Time / 60;
	int seconds = (int) m_Time % 60;

	int digit1(0), digit2(0);

	String stringSeconds;
	stringSeconds = String("") + seconds;
	if(stringSeconds.GetLength() > 1)
	{
		digit1 = stringSeconds.SubString(0,1).ToInteger();
		digit2 = stringSeconds.SubString(1).ToInteger();
	}
	else
	{
		digit2 = stringSeconds.ToInteger();
	}

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateIdentityMatrix());
	//GAME_ENGINE->DrawString(String("") + minutes + " " + seconds,250,100);

	RECT clipGoldTime;
	clipGoldTime.left = m_BmpGoldTimePtr->GetWidth()/2;
	clipGoldTime.right = m_BmpGoldTimePtr->GetWidth();
	clipGoldTime.top = 0;
	clipGoldTime.bottom = m_BmpGoldTimePtr->GetHeight();

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(GAME_ENGINE->GetWidth()-100,12));
	GAME_ENGINE->DrawBitmap(m_BmpGoldTimePtr,0,0,clipGoldTime);

	clipGoldTime.left = 0;
	clipGoldTime.right = m_BmpGoldTimePtr->GetWidth()/2;

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(GAME_ENGINE->GetWidth()-240,12));
	GAME_ENGINE->DrawBitmap(m_BmpGoldTimePtr,0,0,clipGoldTime);

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(10,12));
	GAME_ENGINE->DrawBitmap(m_BmpVitalPtr,0,0);

	int startclip(0);
	int width = m_BmpNumbersPtr->GetWidth()/11;
	int height = m_BmpNumbersPtr->GetHeight()/2;

	switch(minutes)
	{
	case 3:
		startclip = 4;
		break;
	case 2:
		startclip = 3;
		break;
	case 1:
		startclip = 2;
		break;
	case 0:
		startclip = 1;
		break;
	}

	RECT clipminutes;
	clipminutes.left = width * startclip;
	clipminutes.right = clipminutes.left + width;
	clipminutes.top = 0;
	clipminutes.bottom = height;

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(GAME_ENGINE->GetWidth()-60,12));
	GAME_ENGINE->DrawBitmap(m_BmpNumbersPtr,0,0,clipminutes);

	RECT colon;
	colon.left = 0;
	colon.right = width;
	colon.top = 0;
	colon.bottom = height;

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(GAME_ENGINE->GetWidth()-60 + width,12));
	GAME_ENGINE->DrawBitmap(m_BmpNumbersPtr,0,0,colon);

	RECT clipdigit1;
	clipdigit1.left = (digit1 + 1) * width;
	clipdigit1.right = clipdigit1.left + width;
	clipdigit1.top = 0;
	clipdigit1.bottom = height;

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(GAME_ENGINE->GetWidth()-60 + width*2,12));
	GAME_ENGINE->DrawBitmap(m_BmpNumbersPtr,0,0,clipdigit1);

	RECT clipdigit2;
	clipdigit2.left = (digit2 + 1) * width;
	clipdigit2.right = clipdigit2.left + width;
	clipdigit2.top = 0;
	clipdigit2.bottom = height;

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(GAME_ENGINE->GetWidth()-60 + width*3,12));
	GAME_ENGINE->DrawBitmap(m_BmpNumbersPtr,0,0,clipdigit2);

	// Gold

	String money = String("") + m_MoneyCount;

	for(int i = 0; i < money.GetLength(); ++i)
	{
		int digitgold = money.SubString(i,1).ToInteger();

		RECT clipgold;
		clipgold.left = (digitgold + 1) * width;
		clipgold.right = clipgold.left + width;
		clipgold.top = height;
		clipgold.bottom = clipgold.top + height;

		GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(GAME_ENGINE->GetWidth()-165 + width*i,12));
		GAME_ENGINE->DrawBitmap(m_BmpNumbersPtr,0,0,clipgold);
	}

	// bottom HUD

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateTranslationMatrix(0,GAME_ENGINE->GetHeight()-16));
	GAME_ENGINE->DrawBitmap(m_BmpBottombarPtr,0,0);

	GAME_ENGINE->SetTransformMatrix(MATRIX3X2::CreateIdentityMatrix());
	int middlebar = GAME_ENGINE->GetHeight()-m_BmpBottombarPtr->GetHeight()/2 - 1;
	int firepower = m_WillowPtr->GetFirePower();
	if(firepower >= 100) firepower = 100;
	GAME_ENGINE->FillRect(12,middlebar,10 + firepower * 1.5,middlebar + 2);
}