Beispiel #1
0
    public static string StringSubstring(GamePlatform p, string a, int start, int count)
    {
        IntRef aLength = new IntRef();

        int[] aChars = p.StringToCharArray(a, aLength);

        int[] bChars = new int[count];
        for (int i = 0; i < count; i++)
        {
            bChars[i] = aChars[start + i];
        }
        return(p.CharArrayToString(bChars, count));
    }
Beispiel #2
0
    public static string StringAppend(GamePlatform p, string a, string b)
    {
        IntRef aLength = new IntRef();

        int[]  aChars  = p.StringToCharArray(a, aLength);
        IntRef bLength = new IntRef();

        int[] bChars = p.StringToCharArray(b, bLength);

        int[] cChars = new int[aLength.value + bLength.value];
        for (int i = 0; i < aLength.value; i++)
        {
            cChars[i] = aChars[i];
        }
        for (int i = 0; i < bLength.value; i++)
        {
            cChars[i + aLength.value] = bChars[i];
        }
        return(p.CharArrayToString(cChars, aLength.value + bLength.value));
    }
Beispiel #3
0
    public static string StringSubstring(GamePlatform p, string a, int start, int count)
    {
        IntRef aLength = new IntRef();
        int[] aChars = p.StringToCharArray(a, aLength);

        int[] bChars = new int[count];
        for (int i = 0; i < count; i++)
        {
            bChars[i] = aChars[start + i];
        }
        return p.CharArrayToString(bChars, count);
    }
Beispiel #4
0
    public static string StringAppend(GamePlatform p, string a, string b)
    {
        IntRef aLength = new IntRef();
        int[] aChars = p.StringToCharArray(a, aLength);
        IntRef bLength = new IntRef();
        int[] bChars = p.StringToCharArray(b, bLength);

        int[] cChars = new int[aLength.value + bLength.value];
        for (int i = 0; i < aLength.value; i++)
        {
            cChars[i] = aChars[i];
        }
        for (int i = 0; i < bLength.value; i++)
        {
            cChars[i + aLength.value] = bChars[i];
        }
        return p.CharArrayToString(cChars, aLength.value + bLength.value);
    }
Beispiel #5
0
 public string CharToString(int a)
 {
     int[] arr = new int[1];
     arr[0] = a;
     return(p.CharArrayToString(arr, 1));
 }
Beispiel #6
0
    /// <summary>
    /// Split a given string into words with different colors
    /// </summary>
    /// <param name="s">String to split</param>
    /// <param name="defaultcolor">Default color to use when no color code is given</param>
    /// <param name="retLength"><see cref="IntRef"/> the number of text parts will be written to</param>
    /// <returns><see cref="TextPart"/> array containing the processed parts of the given string</returns>
    public TextPart[] DecodeColors(string s, int defaultcolor, IntRef retLength)
    {
        // Maximum word/message length
        int messageMax = 256;
        int wordMax    = 64;

        // Prepare temporary arrays
        TextPart[] parts      = new TextPart[messageMax];
        int        partsCount = 0;

        int[] currenttext       = new int[wordMax];
        int   currenttextLength = 0;
        bool  endCurrentWord    = false;

        // Split the given string into single characters
        IntRef sLength = new IntRef();

        int[] sChars = platform.StringToCharArray(s, sLength);

        // Set default color
        int  currentColor = defaultcolor;
        bool changeColor  = false;
        int  nextColor    = defaultcolor;

        // Process each character
        for (int i = 0; i < sLength.value; i++)
        {
            if (partsCount >= messageMax)
            {
                // Quit parsing text if message has reached maximum length
                break;
            }

            if (endCurrentWord || currenttextLength >= wordMax)
            {
                if (currenttextLength > 0)
                {
                    //Add content so far to return value
                    TextPart part = new TextPart();
                    part.text         = platform.CharArrayToString(currenttext, currenttextLength);
                    part.color        = currentColor;
                    parts[partsCount] = part;
                    partsCount++;
                    currenttextLength = 0;
                }
                endCurrentWord = false;
            }

            if (changeColor)
            {
                currentColor = nextColor;
                changeColor  = false;
            }

            if (sChars[i] == ' ')
            {
                // Begin a new word if a space character is found
                currenttext[currenttextLength] = sChars[i];
                currenttextLength++;
                endCurrentWord = true;
            }
            else if (sChars[i] == '&')
            {
                // If a & is found, try to parse a color code
                if (i + 1 < sLength.value)
                {
                    int color = HexToInt(sChars[i + 1]);
                    if (color != -1)
                    {
                        // Update current color and end word
                        nextColor      = GetColor(color);
                        changeColor    = true;
                        endCurrentWord = true;

                        // Increment i to prevent the code from being read again
                        i++;

                        continue;
                    }
                    else
                    {
                        // No valid color code found. Display as normal character
                        currenttext[currenttextLength] = sChars[i];
                        currenttextLength++;
                    }
                }
                else
                {
                    // End of string. Display as normal character
                    currenttext[currenttextLength] = sChars[i];
                    currenttextLength++;
                }
            }
            else
            {
                // Nothing special. Just add the current character
                currenttext[currenttextLength] = sChars[i];
                currenttextLength++;
            }
        }

        // Add any leftover text parts in current color
        if (currenttextLength != 0 && partsCount < messageMax)
        {
            TextPart part = new TextPart();
            part.text         = platform.CharArrayToString(currenttext, currenttextLength);
            part.color        = currentColor;
            parts[partsCount] = part;
            partsCount++;
        }

        // Set length of returned array and return result
        retLength.value = partsCount;
        return(parts);
    }