상속: IDisposable
예제 #1
0
        public void TryLoad()
        {
            IModuleFileData fileData = null;

            // only load Json
            if (mType == FileType.JSON)
            {
                fileData = new JsonFileData(ResolvedPath);
            }
            else if (mType == FileType.LUA)
            {
                fileData = new LuaFileData(ResolvedPath);
            }

            if (fileData != null)
            {
                fileData.SetModuleFile(this);
                mFileData = fileData as FileData;
                mFileData.Load();

                if (mAlias == "ui:stockpile:filters")
                {
                    foreach (JToken filter in (mFileData as JsonFileData).Json.SelectTokens("stockpile.*.categories.*.filter"))
                    {
                        ModuleDataManager.GetInstance().StockpileFilters.Add(filter.ToString());
                    }
                }

                foreach (KeyValuePair<string, FileData> data in mReferencesCache)
                {
                    mFileData.ReferencedByFileData[data.Key] = data.Value;
                }
            }
        }
예제 #2
0
        public FilePreview(IReloadable owner, FileData fileData)
        {
            mFileData = fileData;
            InitializeComponent();
            textBox.Text = mFileData.FlatFileData;
            mOwner = owner;

            this.configureScintilla();
        }
예제 #3
0
#pragma warning disable SA1202 // Elements must be ordered by access
        public void Dispose()
#pragma warning restore SA1202 // Elements must be ordered by access
        {
            mModule = null;
            mReferencesCache.Clear();
            if (mFileData != null)
            {
                FileData data = mFileData;
                mFileData = null;
                data.Dispose();
            }
        }
예제 #4
0
        private FileData FindFileData(FileData start, string[] path, int startIndex)
        {
            if (startIndex >= path.Length || start == null)
            {
                return start;
            }

            string subfileName = path[startIndex];
            FileData found = null;
            foreach (FileData openedFile in start.OpenedFiles)
            {
                if (openedFile.FileName.Equals(subfileName))
                {
                    found = openedFile;
                    break;
                }
            }

            if (found == null)
            {
                foreach (FileData openedFile in start.RelatedFiles)
                {
                    if (openedFile.FileName.Equals(subfileName))
                    {
                        found = openedFile;
                        break;
                    }
                }
            }

            return FindFileData(found, path, startIndex + 1);
        }
예제 #5
0
 public void AddReference(string name, FileData fileData)
 {
     if (FileData != null)
     {
         FileData.ReferencedByFileData[name] = fileData;
     }
     else
     {
         mReferencesCache[name] = fileData;
     }
 }
예제 #6
0
        private void addGhostToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode     = treeView.SelectedNode;
            FileData selectedFileData = ModuleDataManager.GetInstance().GetSelectedFileData(treeView.SelectedNode);

            if (!CanAddEntityForm(selectedFileData, "ghost"))
            {
                return;
            }

            JsonFileData jsonFileData     = selectedFileData as JsonFileData;
            string       originalFileName = jsonFileData.FileName;
            string       ghostFilePath    = jsonFileData.Directory + "/" + originalFileName + "_ghost.json";

            try
            {
                JObject ghostJson = new JObject();
                ghostJson.Add("type", "entity");

                // Get a linked qb file
                string qbFilePath = null;
                foreach (FileData data in jsonFileData.LinkedFileData.Values)
                {
                    if (data is QubicleFileData)
                    {
                        qbFilePath = data.Path;
                    }
                }

                JObject ghostComponents = new JObject();
                ghostJson["components"] = ghostComponents;

                JObject json = jsonFileData.Json;
                JObject existingComponents = json["components"] as JObject;
                if (existingComponents != null)
                {
                    TryMoveJToken("unit_info", existingComponents, ghostComponents);
                    TryMoveJToken("render_info", existingComponents, ghostComponents);
                    TryMoveJToken("mob", existingComponents, ghostComponents);

                    // Only move the default model variant to the ghost:
                    JObject defaultModelVariant = existingComponents["model_variants"] as JObject;
                    if (defaultModelVariant != null && defaultModelVariant.Count == 1)
                    {
                        TryMoveJToken("model_variants", existingComponents, ghostComponents);
                    }
                    else
                    {
                        JObject modelVariants = new JObject();
                        ghostComponents["model_variants"] = modelVariants;
                        TryMoveJToken("default", defaultModelVariant, modelVariants);
                    }
                }

                string ghostJsonString = JsonHelper.GetFormattedJsonString(ghostJson);
                using (StreamWriter wr = new StreamWriter(ghostFilePath, false, new UTF8Encoding(false)))
                {
                    wr.Write(ghostJsonString);
                }

                JToken entityFormsComponent = json.SelectToken("components.stonehearth:entity_forms");
                if (entityFormsComponent == null)
                {
                    if (json["components"] == null)
                    {
                        json["components"] = new JObject();
                    }

                    JObject entityForms = new JObject();
                    json["components"]["stonehearth:entity_forms"] = entityForms;
                    entityFormsComponent = entityForms;
                }

                JToken mixins = json["mixins"];
                if (mixins == null)
                {
                    json.First.AddAfterSelf(new JProperty("mixins", "file(" + originalFileName + "_ghost.json" + ")"));
                }
                else
                {
                    JArray mixinsArray = mixins as JArray;
                    if (mixinsArray == null)
                    {
                        mixinsArray    = new JArray();
                        json["mixins"] = mixinsArray;
                        mixinsArray.Add(mixins.ToString());
                    }

                    mixinsArray.Add("file(" + originalFileName + "_ghost.json" + ")");
                }

                (entityFormsComponent as JObject).Add("ghost_form", "file(" + originalFileName + "_ghost.json" + ")");
                jsonFileData.TrySetFlatFileData(jsonFileData.GetJsonFileString());
                jsonFileData.TrySaveFile();
                MessageBox.Show("Adding file " + ghostFilePath);
            }
            catch (Exception ee)
            {
                MessageBox.Show("Unable to add iconic file because " + ee.Message);
                return;
            }

            Reload();
        }
예제 #7
0
        private void addIconicVersionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode     = treeView.SelectedNode;
            FileData selectedFileData = ModuleDataManager.GetInstance().GetSelectedFileData(treeView.SelectedNode);

            if (!CanAddEntityForm(selectedFileData, "iconic"))
            {
                return;
            }

            JsonFileData jsonFileData     = selectedFileData as JsonFileData;
            string       originalFileName = jsonFileData.FileName;
            string       iconicFilePath   = jsonFileData.Directory + "/" + originalFileName + "_iconic.json";

            try
            {
                string iconicJson = System.Text.Encoding.UTF8.GetString(StonehearthEditor.Properties.Resources.defaultIconic);
                if (iconicJson != null)
                {
                    // Get a linked qb file
                    string newQbFile                = null;
                    JToken defaultModelVariant      = jsonFileData.Json.SelectToken("components.model_variants.default");
                    string defaultModelVariantNames = defaultModelVariant != null?defaultModelVariant.ToString() : "";

                    foreach (FileData data in jsonFileData.LinkedFileData.Values)
                    {
                        if (data is QubicleFileData)
                        {
                            string fileName = data.FileName + ".qb";
                            if (defaultModelVariantNames.Contains(fileName))
                            {
                                CloneObjectParameters parameters = new CloneObjectParameters();
                                parameters.AddStringReplacement(data.FileName, data.FileName + "_iconic");
                                newQbFile = data.Path.Replace(".qb", "_iconic.qb");
                                data.Clone(newQbFile, parameters, new HashSet <string>(), true);
                            }
                        }
                    }

                    if (newQbFile != null)
                    {
                        string relativePath = JsonHelper.MakeRelativePath(iconicFilePath, newQbFile);
                        iconicJson = iconicJson.Replace("default_iconic.qb", relativePath);
                    }

                    try
                    {
                        JObject parsedIconicJson = JObject.Parse(iconicJson);
                        iconicJson = JsonHelper.GetFormattedJsonString(parsedIconicJson); // put it in the parser and back again to make sure we get valid json.

                        using (StreamWriter wr = new StreamWriter(iconicFilePath, false, new UTF8Encoding(false)))
                        {
                            wr.Write(iconicJson);
                        }
                    }
                    catch (Exception e2)
                    {
                        MessageBox.Show("Unable to write new iconic file because " + e2.Message);
                        return;
                    }

                    JObject json = jsonFileData.Json;
                    JToken  entityFormsComponent = json.SelectToken("components.stonehearth:entity_forms");
                    if (entityFormsComponent == null)
                    {
                        if (json["components"] == null)
                        {
                            json["components"] = new JObject();
                        }

                        JObject entityForms = new JObject();
                        json["components"]["stonehearth:entity_forms"] = entityForms;
                        entityFormsComponent = entityForms;
                    }

                    (entityFormsComponent as JObject).Add("iconic_form", "file(" + originalFileName + "_iconic.json" + ")");
                    jsonFileData.TrySetFlatFileData(jsonFileData.GetJsonFileString());
                    jsonFileData.TrySaveFile();
                    MessageBox.Show("Adding file " + iconicFilePath);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("Unable to add iconic file because " + ee.Message);
                return;
            }

            Reload();
        }
예제 #8
0
 public PreviewCloneAliasCallback(ManifestView viewer, FileData fileData, CloneObjectParameters parameters)
 {
     mViewer     = viewer;
     mFileData   = fileData;
     mParameters = parameters;
 }
예제 #9
0
 public CloneAliasCallback(ManifestView viewer, FileData file)
 {
     mViewer   = viewer;
     mFileData = file;
 }
예제 #10
0
        private void ParseJsonSpecificData()
        {
            string directory        = Directory;
            string categoryOverride = null;

            switch (mJsonType)
            {
            case JSONTYPE.ENTITY:
                JToken entityFormsComponent = mJson.SelectToken("components.stonehearth:entity_forms");
                if (entityFormsComponent != null)
                {
                    JToken iconicForm = entityFormsComponent["iconic_form"];
                    if (iconicForm != null)
                    {
                        string iconicFilePath = JsonHelper.GetFileFromFileJson(iconicForm.ToString(), directory);
                        iconicFilePath = JsonHelper.NormalizeSystemPath(iconicFilePath);
                        JsonFileData iconic = new JsonFileData(iconicFilePath);
                        iconic.Load();
                        categoryOverride = iconic.Category;
                        Category         = iconic.Category;
                        OpenedFiles.Add(iconic);
                    }

                    // Look for stonehearth:entity_forms
                    JToken ghostForm = entityFormsComponent["ghost_form"];
                    if (ghostForm != null)
                    {
                        string ghostFilePath = JsonHelper.GetFileFromFileJson(ghostForm.ToString(), directory);
                        ghostFilePath = JsonHelper.NormalizeSystemPath(ghostFilePath);
                        JsonFileData ghost = new JsonFileData(ghostFilePath);
                        ghost.Category = categoryOverride;
                        ghost.Load();
                        ghost.AddMixin("stonehearth:mixins:placed_object");
                        OpenedFiles.Add(ghost);
                        ghost.PostLoad();
                    }

                    CheckForNoNetWorth();
                }
                else
                {
                    // Make sure to check if items have no net worth or set mNetWorth from their net worth data
                    JToken catalog_data = mJson.SelectToken("entity_data.stonehearth:catalog.is_item");
                    if (catalog_data != null && catalog_data.Value <bool>())
                    {
                        CheckForNoNetWorth();
                    }

                    if (GetModuleFile() != null && mJson.SelectToken("components.item") != null)
                    {
                        CheckForNoNetWorth();
                    }

                    if (mJson.SelectToken("entity_data.stonehearth:net_worth") != null)
                    {
                        CheckForNoNetWorth();
                    }
                }

                break;

            case JSONTYPE.JOB:
                // Parse crafter stuff
                JToken crafter = mJson["crafter"];
                if (crafter != null)
                {
                    // This is a crafter, load its recipes
                    string recipeListLocation = crafter["recipe_list"].ToString();
                    recipeListLocation = JsonHelper.GetFileFromFileJson(recipeListLocation, directory);
                    if (recipeListLocation != null)
                    {
                        JsonFileData recipes = new JsonFileData(recipeListLocation);
                        recipes.Load();
                        foreach (FileData recipe in recipes.LinkedFileData.Values)
                        {
                            recipes.RelatedFiles.Add(recipe);
                        }

                        OpenedFiles.Add(recipes);
                        recipes.ReferencedByFileData[GetAliasOrFlatName()] = this;
                    }
                }

                JObject jobEquipment = mJson["equipment"] as JObject;
                if (jobEquipment != null)
                {
                    foreach (JToken equippedItem in jobEquipment.Children())
                    {
                        string   equipmentJson = equippedItem.Last.ToString();
                        FileData fileData      = null;
                        if (equipmentJson.IndexOf(':') >= 0)
                        {
                            foreach (ModuleFile alias in LinkedAliases)
                            {
                                if (alias.FullAlias.Equals(equipmentJson))
                                {
                                    fileData = alias.FileData;
                                }
                            }
                        }
                        else
                        {
                            equipmentJson = JsonHelper.GetFileFromFileJson(equipmentJson, directory);
                            LinkedFileData.TryGetValue(equipmentJson, out fileData);
                        }

                        JsonFileData jsonFileData = fileData as JsonFileData;
                        if (jsonFileData != null)
                        {
                            JToken equipment_piece = jsonFileData.mJson.SelectToken("components.stonehearth:equipment_piece");
                            if (equipment_piece != null)
                            {
                                JToken ilevel = equipment_piece["ilevel"];
                                if (ilevel != null && ilevel.Value <int>() > 0)
                                {
                                    JToken noDrop = equipment_piece["no_drop"];
                                    if (noDrop == null || !noDrop.Value <bool>())
                                    {
                                        AddError("Equipment piece " + equipmentJson + " is not set to no_drop=true even through it is a job equipment!");
                                    }
                                }
                            }
                        }
                    }
                }

                ////AlterJobExperience();
                break;

            case JSONTYPE.RECIPE:
                JToken portrait = mJson["portrait"];
                if (portrait != null)
                {
                    string portraitImageLocation = portrait.ToString();
                    portraitImageLocation = JsonHelper.GetFileFromFileJson(portraitImageLocation, directory);
                    ImageFileData image = new ImageFileData(portraitImageLocation);
                    LinkedFileData.Add(portraitImageLocation, image);
                }

                break;

            case JSONTYPE.AI_PACK:
                JArray actions = mJson["actions"] as JArray;
                if (actions != null)
                {
                    foreach (JToken action in actions)
                    {
                        string     fullAlias   = action.ToString();
                        ModuleFile linkedAlias = ModuleDataManager.GetInstance().GetModuleFile(fullAlias);
                        if (linkedAlias == null)
                        {
                            AddError("links to alias " + fullAlias + " which does not exist!");
                        }
                    }
                }
                break;

            case JSONTYPE.MONSTER_TUNING:
                JToken experience = mJson.SelectToken("attributes.exp_reward");
                if (experience != null)
                {
                    //Console.WriteLine(GetAliasOrFlatName() + "\t" + experience.ToString());
                }
                break;
            }

            FixUnitInfo();
            CheckDisplayName();
            FixUpAllCombatData();
        }