AGS.Types.Game.SetScriptAPIForOldProject C# (CSharp) Method

SetScriptAPIForOldProject() public method

public SetScriptAPIForOldProject ( ) : void
return void
        public void SetScriptAPIForOldProject()
        {
            // Try to find corresponding ScriptAPI for older version game project that did not have such setting
            System.Version projectVersion = _savedXmlEditorVersion != null ? new System.Version(_savedXmlEditorVersion) : null;
            System.Version firstCompatibleVersion = new System.Version(_firstScriptAPICompatibleVersion);
            if (projectVersion == null)
            {
                _settings.ScriptCompatLevel = ScriptAPIVersion.v321;
            }
            else if (projectVersion < firstCompatibleVersion)
            {
                // Devise the API version from enum values Description attribute
                // and find the first version equal or higher than project's one.
                Type t = typeof(ScriptAPIVersion);
                string[] names = Enum.GetNames(t);
                foreach (string n in names)
                {
                    FieldInfo fi = t.GetField(n);
                    DescriptionAttribute[] attributes =
                      (DescriptionAttribute[])fi.GetCustomAttributes(
                      typeof(DescriptionAttribute), false);
                    if (attributes.Length == 0)
                        continue;
                    System.Version v = new System.Version(attributes[0].Description);
                    if (projectVersion <= v)
                    {
                        _settings.ScriptCompatLevel = (ScriptAPIVersion)Enum.Parse(t, n);
                        break;
                    }
                }
            }
        }

Usage Example

Beispiel #1
0
        private void SetDefaultValuesForNewFeatures(Game game)
        {
            int xmlVersionIndex = 0;
            if (game.SavedXmlVersionIndex.HasValue)
            {
                xmlVersionIndex = game.SavedXmlVersionIndex.Value;
            }

            if (xmlVersionIndex < 2)
            {
                // Upgrade old games to use the Anti-Glide Mode setting
                foreach (Character character in game.RootCharacterFolder.AllItemsFlat)
                {
                    character.MovementLinkedToAnimation = game.Settings.AntiGlideMode;
                }
            }

            if (xmlVersionIndex < 3)
            {
                // Upgrade old games to flatten the dialog scripts
                foreach (Dialog dialog in game.RootDialogFolder.AllItemsFlat)
                {
                    dialog.Script = RemoveAllLeadingSpacesFromLines(dialog.Script);
                }
            }

            game.SetScriptAPIForOldProject();
        }