Beispiel #1
0
 public Game(string word, GameLanguage lang)
 {
     Word = word;
     Lenght = Word.Length;
     Stage = 0;
     InitializeAlphabet(lang);
 }
 /// <summary>
 /// Sets the value of a string for a given language.
 /// </summary>
 /// <param name="str">The string.</param>
 /// <param name="language">The language.</param>
 /// <param name="newValue">The new value. Can be <c>null</c>.</param>
 public void SetString(LocalizedString str, GameLanguage language, string newValue)
 {
     // Replace the string
     var offset = str.Offsets[(int)language];
     if (offset < 0 || offset >= Data.Length)
         offset = Data.Length; // Add the string at the end
     var oldLength = GetStringLength(offset);
     var bytes = (newValue != null) ? Encoding.UTF8.GetBytes(newValue) : new byte[0];
     if (bytes.Length > 0 && offset == Data.Length)
     {
         // If it's a new string, null-terminate it
         var nullTerminated = new byte[bytes.Length + 1];
         Buffer.BlockCopy(bytes, 0, nullTerminated, 0, bytes.Length);
         bytes = nullTerminated;
     }
     Data = ArrayUtil.Replace(Data, offset, oldLength, bytes);
     
     // Update string offsets
     str.Offsets[(int)language] = (bytes.Length > 0) ? offset : -1;
     var sizeDelta = bytes.Length - oldLength;
     foreach (var adjustStr in Strings)
     {
         for (var i = 0; i < adjustStr.Offsets.Length; i++)
         {
             if (adjustStr.Offsets[i] > offset)
                 adjustStr.Offsets[i] += sizeDelta;
         }
     }
 }
 public GameManager(Game theGame)
 {
     mGame = theGame;
     mGraphicsDevice = theGame.GraphicsDevice;
     mGameStates = new List<GameState>();
     mCurrentLang = GameLanguage.ENGLISH;
 }
        /// <summary>
        /// Gets the value of a string in a given language.
        /// </summary>
        /// <param name="str">The string.</param>
        /// <param name="language">The language.</param>
        /// <returns>The value of the string, or <c>null</c> if the string is not available.</returns>
        public string GetString(LocalizedString str, GameLanguage language)
        {
            var offset = str.Offsets[(int)language];
            if (offset < 0 || offset >= Data.Length)
                return null; // String not available

            var length = GetStringLength(offset);
            return Encoding.UTF8.GetString(Data, offset, length);
        }
Beispiel #5
0
        public ThirdGenLanguage(GameLanguage language, StructureValueCollection values, FileSegmenter segmenter,
			FileSegmentGroup localeArea, EngineDescription buildInfo)
        {
            Language = language;
            _pointerLayout = buildInfo.Layouts.GetLayout("locale index table entry");
            _encryptionKey = buildInfo.LocaleKey;
            _sizeAlign = (_encryptionKey != null) ? AES.BlockSize : 1;
            Load(values, segmenter, localeArea);
        }
    // Use this for initialization
    public UserSettings()
    {
        //load settings
        mVolume = PlayerPrefs.GetFloat(volumeKey, 1.0f);

        mMute = PlayerPrefs.GetInt(muteKey, muteDefault) > 0;

        ApplyAudioSettings();

        mLanguage = (GameLanguage)PlayerPrefs.GetInt(languageKey, (int)GameLanguage.English);
    }
		/// <summary>
		/// Loads the language pack for a language.
		/// </summary>
		/// <param name="language">The language of the pack to load.</param>
		/// <param name="reader">The stream to read from.</param>
		/// <returns>
		/// The language pack that was loaded, or <c>null</c> if no pack exists for the language.
		/// </returns>
		public LanguagePack LoadLanguage(GameLanguage language, IReader reader)
		{
			if (_languageGlobals == null)
				return null;

			var data = _languageGlobals.Languages[(int)language];
			var table = data.LoadStrings(reader);
			var pack = new LanguagePack(language);
			foreach (var group in _groupsByTag.Values)
				pack.AddStringList(CreateList(group, (int)language, table));
			return pack;
		}
		/// <summary>
		/// Loads the language pack for a language.
		/// </summary>
		/// <param name="language">The language of the pack to load.</param>
		/// <param name="reader">The stream to read from.</param>
		/// <returns>
		/// The language pack that was loaded, or <c>null</c> if no pack exists for the language.
		/// </returns>
		public LanguagePack LoadLanguage(GameLanguage language, IReader reader)
		{
			LanguagePack result;
			if (!_cachedPacks.TryGetValue(language, out result))
			{
				// Not in the cache - load it from disk and store it
				result = _baseLoader.LoadLanguage(language, reader);
				if (result != null)
					_cachedPacks[language] = result;
			}
			return result;
		}
 public static void Load(GameLanguage language)
 {
     string filename = string.Empty;
     switch (language)
     {
         case GameLanguage.English:
             filename = EnglishConfig;
             break;
         case GameLanguage.Português:
             filename = PortuguesConfig;
             break;
     }
     _config = Serializer<LanguageConfig>.DeserializeObject(filename);
 }
Beispiel #10
0
		public LocaleEditor(GameLanguage language, ICacheFile cache, IStreamManager streamManager, Trie stringIdTrie,
			LocaleSymbolCollection symbols)
		{
			InitializeComponent();

			_currentLanguage = language;
			_cache = cache;
			_streamManager = streamManager;
			_symbols = symbols;
			StringIDTrie = stringIdTrie;

			// Thread the loading routine
			var thrd = new Thread(LoadAll);
			thrd.SetApartmentState(ApartmentState.STA);
			thrd.Start();
		}
Beispiel #11
0
    /// <summary>
    /// Make sure to call this during Main's initialization based on user settings for language.
    /// </summary>
    public void Load(GameLanguage language)
    {
        int langInd = (int)language;

        TableData dat = tables[langInd];

        fastJSON.JSON.Instance.Parameters.UseExtensions = false;
        List<Entry> tableEntries = fastJSON.JSON.Instance.ToObject<List<Entry>>(dat.file.text);

        mTable = new Dictionary<string, string>(tableEntries.Count);

        foreach(Entry entry in tableEntries) {
            mTable.Add(entry.key, entry.text);
        }

        //append platform specific entries
        TableDataPlatform platform = null;
        foreach(TableDataPlatform platformDat in dat.platforms) {
            if(platformDat.platform == GamePlatform.current) {
                platform = platformDat;
                break;
            }
        }

        if(platform != null) {
            List<Entry> platformEntries = fastJSON.JSON.Instance.ToObject<List<Entry>>(dat.file.text);

            foreach(Entry platformEntry in platformEntries) {
                if(mTable.ContainsKey(platformEntry.key)) {
                    mTable[platformEntry.key] = platformEntry.text;
                }
            }
        }

        //already loaded before? then let everyone know it has changed
        if(mLoaded) {
            SceneManager.RootBroadcastMessage("OnLocalize", null, SendMessageOptions.DontRequireReceiver);
        }
        else {
            mLoaded = true;
        }
    }
 /// <summary>
 /// Filters a set of localized strings and prepares them for display.
 /// </summary>
 /// <param name="unic">The string list.</param>
 /// <param name="stringIds">The string ID cache to use.</param>
 /// <param name="strings">The strings to display.</param>
 /// <param name="language">The language to display strings from.</param>
 /// <param name="filter">The filter to match strings and stringIDs against. Can be <c>null</c> to display everything.</param>
 /// <returns>The strings to print.</returns>
 public static List<DisplayString> PrepareForDisplay(MultilingualUnicodeStringList unic, StringIDCache stringIds, IEnumerable<LocalizedString> strings, GameLanguage language, string filter)
 {
     // Filter the input strings
     var display = new List<DisplayString>();
     foreach (var localizedString in strings)
     {
         var str = unic.GetString(localizedString, language);
         if (str == null)
             continue;
         var stringId = stringIds.GetString(localizedString.StringID);
         if (filter != null && !str.Contains(filter) && !stringId.Contains(filter))
             continue;
         display.Add(new DisplayString
         {
             StringID = stringId,
             String = str
         });
     }
     display.Sort((a, b) => String.Compare(a.StringID, b.StringID, StringComparison.Ordinal));
     return display;
 }
Beispiel #13
0
		/// <summary>
		/// Initializes a new instance of the <see cref="LanguagePack"/> class.
		/// </summary>
		/// <param name="language">The language that the pack targets.</param>
		public LanguagePack(GameLanguage language)
		{
			Language = language;
		}
Beispiel #14
0
 private void InitializeAlphabet(GameLanguage lang)
 {
     switch (lang)
     {
         case GameLanguage.En:
             Alphabet = new char[] {'A', 'B', 'C', 'D', 'E',
                 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
                 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
                 'X', 'Y', 'Z'};
             break;
         case GameLanguage.Ru:
             Alphabet = new char[] {'А', 'Б', 'В', 'Г', 'Д', 'Е',
                 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О',
                 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш',
                 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я'};
             break;
     }
 }
 public static void Save(GameLanguage language)
 {
     string filename = string.Empty;
     switch (language)
     {
         case GameLanguage.English:
             filename = EnglishConfig;
             break;
         case GameLanguage.Português:
             filename = PortuguesConfig;
             break;
     }
     Serializer<LanguageConfig>.Save(Config, filename);
 }
Beispiel #16
0
        private void AddLanguage(string name, GameLanguage lang)
        {
            if (!_cacheFile.Languages.AvailableLanguages.Contains(lang))
                return;

            _languages.Add(new LanguageEntry(name, lang));
        }
Beispiel #17
0
 public LanguageEntry(string name, GameLanguage lang)
 {
     Name = name;
     Language = lang;
 }
 /// <summary>
 ///     Loads the language pack for a language.
 /// </summary>
 /// <param name="language">The language of the pack to load.</param>
 /// <param name="reader">The stream to read from.</param>
 /// <returns>
 ///     The language pack that was loaded, or <c>null</c> if no pack exists for the language.
 /// </returns>
 public ILanguagePack LoadLanguage(GameLanguage language, IReader reader)
 {
     return null;
 }
 public static bool ParseLanguage(string name, out GameLanguage result)
 {
     return _languages.TryGetValue(name, out result);
 }
		/// <summary>
		/// Determines whether or not a language pack is in the cache.
		/// </summary>
		/// <param name="language">The language to check.</param>
		/// <returns><c>true</c> if the language's pack is in the cache.</returns>
		public bool IsCached(GameLanguage language)
		{
			return _cachedPacks.ContainsKey(language);
		}
 /// <summary>
 ///     Loads the language pack for a language.
 /// </summary>
 /// <param name="language">The language of the pack to load.</param>
 /// <param name="reader">The stream to read from.</param>
 /// <returns>
 ///     The language pack that was loaded, or <c>null</c> if no pack exists for the language.
 /// </returns>
 public ILanguagePack LoadLanguage(GameLanguage language, IReader reader)
 {
     ThirdGenLanguage data = _languageGlobals.Languages[(int) language];
     return new ThirdGenLanguagePack(data, _groups, reader);
 }