Пример #1
0
        public override void SaveCell(HashSet <JsonFileData> modifiedFiles, RecipeRow row, object value)
        {
            JsonFileData jsonFileData = row.Item;
            JObject      json         = jsonFileData.Json;
            JToken       token        = json.SelectToken("entity_data.stonehearth:appeal.appeal");

            if (value == null || value == DBNull.Value)
            {
                if (token != null)
                {
                    json.SelectToken("entity_data.stonehearth:appeal").Parent.Remove();
                }
            }
            else if (token != null)
            {
                (token as JValue).Value = (int)value;
            }
            else
            {
                JObject entityData = json["entity_data"] as JObject;
                if (entityData == null)
                {
                    entityData          = new JObject();
                    json["entity_data"] = entityData;
                }

                JObject appealData = new JObject(new JProperty("appeal", (int)value));
                entityData.Add("stonehearth:appeal", appealData);
            }

            modifiedFiles.Add(jsonFileData);
        }
Пример #2
0
        public override bool TryDeleteCell(RecipeRow row)
        {
            Ingredient ingredient = row.GetOrAddIngredient(this.columnGroup);

            ingredient.Name = "";
            return(true);
        }
Пример #3
0
        public override void OnDataCellChanged(DataColumnChangeEventArgs e)
        {
            // grab col and change the image
            RecipeRow  row        = (RecipeRow)e.Row;
            string     newName    = e.ProposedValue == DBNull.Value || e.ProposedValue == null ? "" : (string)e.ProposedValue;
            Ingredient ingredient = row.GetOrAddIngredient(this.columnGroup);

            if (IsMaterial(newName))
            {
                ingredient.Icon = recipesView.GetIcon(newName);
            }
            else
            {
                JsonFileData jsonFileData = (JsonFileData)ModuleDataManager.GetInstance().GetModuleFile(newName).FileData;
                ingredient.Icon = recipesView.GetIcon(jsonFileData);
            }

            if (newName == "")
            {
                ingredient.Amount = null;
            }
            else if (ingredient.Amount == null)
            {
                ingredient.Amount = 1;
            }
        }
Пример #4
0
        public override void SaveCell(HashSet <JsonFileData> modifiedFiles, RecipeRow row, object value)
        {
            JsonFileData jsonFileData = row.Item;

            foreach (JsonFileData file in jsonFileData.OpenedFiles)
            {
                JObject json      = file.Json;
                JValue  nameToken = json.SelectToken("entity_data.stonehearth:catalog.display_name") as JValue;
                if (nameToken != null)
                {
                    string locKey = nameToken.Value.ToString();

                    if (!locKey.Contains(":"))
                    {
                        nameToken.Value = (string)value;
                        modifiedFiles.Add(jsonFileData);
                    }
                    else
                    {
                        int i18nLength = "i18n(".Length;
                        locKey = locKey.Substring(i18nLength, locKey.Length - i18nLength - 1);
                        ModuleDataManager.GetInstance().ChangeEnglishLocValue(locKey, (string)value);
                    }
                }
            }
        }
Пример #5
0
        private void openJSONToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewCell cell      = recipesGridView.CurrentCell;
            RecipeRow        recipeRow = mDataTable.GetRow(cell.RowIndex);

            System.Diagnostics.Process.Start(recipeRow.Item.Path);
        }
Пример #6
0
        public override void SaveCell(HashSet <JsonFileData> modifiedFiles, RecipeRow row, object value)
        {
            JsonFileData jsonFileData = row.Item;
            JObject      json         = jsonFileData.Json;
            JToken       token        = json.SelectToken("entity_data.stonehearth:item_quality.variable_quality");

            if (value == null || value == DBNull.Value || !(bool)value)
            {
                if (token != null)
                {
                    json.SelectToken("entity_data.stonehearth:item_quality").Parent.Remove();
                }
            }
            else if (token != null)
            {
                (token as JValue).Value = true;
            }
            else
            {
                JObject entityData = json["entity_data"] as JObject;
                if (entityData == null)
                {
                    entityData          = new JObject();
                    json["entity_data"] = entityData;
                }

                entityData.Add("stonehearth:item_quality", new JObject(new JProperty("variable_quality", true)));
            }

            modifiedFiles.Add(jsonFileData);
        }
Пример #7
0
        private void AddDataTableEventHandlers(DataTable dataTable)
        {
            dataTable.ColumnChanging +=
                (object sender, DataColumnChangeEventArgs e) =>
            {
                if (!mIsLoading && !mIsApplyingChanges)
                {
                    DataCell           cell   = new DataCell(e.Column, (RecipeRow)e.Row);
                    MultipleCellChange change = new MultipleCellChange(cell, e.Row[e.Column], e.ProposedValue);
                    mUndoStack.Push(change);
                }
            };

            dataTable.ColumnChanged +=
                (object sender, DataColumnChangeEventArgs e) =>
            {
                RecipeRow  row    = (RecipeRow)e.Row;
                DataColumn column = e.Column;
                mDataTable.GetColumnBehavior(column).OnDataCellChanged(e);

                if (!mIsLoading)
                {
                    unsavedFilesLabel.Visible = true;
                    mModifiedCells.Add(new DataCell(column, row));
                }
            };
        }
Пример #8
0
        private void DeleteCurrentCell()
        {
            DataGridViewCell cell       = recipesGridView.CurrentCell;
            DataColumn       dataColumn = mDataTable.GetColumn(cell.ColumnIndex);
            RecipeRow        recipeRow  = mDataTable.GetRow(cell.RowIndex);

            mDataTable.GetColumnBehavior(dataColumn).TryDeleteCell(recipeRow);
        }
Пример #9
0
        public override void SaveCell(HashSet <JsonFileData> modifiedFiles, RecipeRow row, object value)
        {
            JsonFileData jsonFileData = row.Recipe;
            JObject      json         = jsonFileData.Json;

            SetJsonField(json, "level_requirement", new JValue((int)value));
            modifiedFiles.Add(jsonFileData);
        }
Пример #10
0
        private void addNewIngredientToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewCell cell      = recipesGridView.CurrentCell;
            RecipeRow        recipeRow = mDataTable.GetRow(cell.RowIndex);

            recipeRow.AddNewIngredient();
            ConfigureColumns();
        }
Пример #11
0
        private void LoadIconics()
        {
            Dictionary <string, JsonFileData> iconicJsonFiles = ModuleDataManager.GetInstance().GetIconicJsons(mBaseModsOnly);

            foreach (KeyValuePair <string, JsonFileData> entry in iconicJsonFiles)
            {
                RecipeRow row = mDataTable.NewRecipeRow();
                SetRowDataForItem(row, entry.Key, entry.Value);
                mDataTable.Rows.Add(row);
            }
        }
Пример #12
0
        private void LoadEntities()
        {
            Dictionary <string, JsonFileData> entityJsonFiles = ModuleDataManager.GetInstance().GetJsonsOfType(JSONTYPE.ENTITY, mBaseModsOnly)
                                                                .Where(kvp => kvp.Value.Json.SelectToken("components.stonehearth:ai") == null)
                                                                .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            foreach (KeyValuePair <string, JsonFileData> entry in entityJsonFiles)
            {
                RecipeRow row = mDataTable.NewRecipeRow();
                SetRowDataForItem(row, entry.Key, entry.Value);
                mDataTable.Rows.Add(row);
            }
        }
Пример #13
0
        public override void SaveCell(HashSet <JsonFileData> modifiedFiles, RecipeRow row, object value)
        {
            JsonFileData jsonFileData = row.Item;
            JObject      json         = jsonFileData.Json;
            JToken       token        = json.SelectToken("entity_data.stonehearth:shop_info.sellable");

            if (value == null || value == DBNull.Value)
            {
                if (token != null)
                {
                    json.SelectToken("entity_data.stonehearth:shop_info.sellable").Parent.Remove();
                }
            }
            else if (token != null)
            {
                (token as JValue).Value = (bool)value;
            }
            else
            {
                JObject entityData = json["entity_data"] as JObject;
                if (entityData == null)
                {
                    entityData          = new JObject();
                    json["entity_data"] = entityData;
                }

                JObject netWorthData = entityData["stonehearth:net_worth"] as JObject;
                if (netWorthData == null)
                {
                    netWorthData = new JObject();
                    json["stonehearth:net_worth"] = netWorthData;
                }

                JObject shopInfo = netWorthData["shop_info"] as JObject;
                if (shopInfo == null)
                {
                    shopInfo          = new JObject();
                    json["shop_info"] = shopInfo;
                }

                shopInfo["sellable"] = (bool)value;
            }

            modifiedFiles.Add(jsonFileData);
        }
Пример #14
0
        public override void SaveCell(HashSet <JsonFileData> modifiedFiles, RecipeRow row, object value)
        {
            JsonFileData jsonFileData = row.Recipe;
            JObject      json         = jsonFileData.Json;

            if (value == null || value == DBNull.Value)
            {
                if (json["work_units"] != null)
                {
                    json.Remove("work_units");
                }
            }
            else
            {
                SetJsonField(json, "work_units", new JValue((int)value));
            }

            modifiedFiles.Add(jsonFileData);
        }
Пример #15
0
        private void SaveIngredients(HashSet <JsonFileData> modifiedFiles, RecipeRow row)
        {
            JsonFileData jsonFileData = row.Recipe;
            JObject      json         = jsonFileData.Json;

            JArray newIngrArray = new JArray();

            foreach (Ingredient ingredient in row.Ingredients)
            {
                if (!string.IsNullOrEmpty(ingredient.Name))
                {
                    string  ingrKey = ingredient.Name.Contains(':') ? "uri" : "material";
                    JObject newIngr = new JObject(
                        new JProperty(ingrKey, ingredient.Name),
                        new JProperty("count", ingredient.Amount));

                    newIngrArray.Add(newIngr);
                }
            }

            json["ingredients"] = newIngrArray;
            modifiedFiles.Add(jsonFileData);
        }
Пример #16
0
        public override void SaveCell(HashSet <JsonFileData> modifiedFiles, RecipeRow row, object value)
        {
            JsonFileData jsonFileData = row.Item;
            JObject      json         = jsonFileData.Json;
            JValue       token        = json.SelectToken("entity_data.stonehearth:net_worth.value_in_gold") as JValue;

            if (value == null || value == DBNull.Value)
            {
                if (token != null)
                {
                    json.SelectToken("entity_data.stonehearth:net_worth.value_in_gold").Parent.Remove();
                }
            }
            else if (token != null)
            {
                token.Value = (int)value;
            }
            else
            {
                JObject entityData = json["entity_data"] as JObject;
                if (entityData == null)
                {
                    entityData          = new JObject();
                    json["entity_data"] = entityData;
                }

                JObject netWorthData = entityData["stonehearth:net_worth"] as JObject;
                if (netWorthData == null)
                {
                    netWorthData = new JObject();
                    json["stonehearth:net_worth"] = netWorthData;
                }

                netWorthData["value_in_gold"] = (int)value;
            }
            modifiedFiles.Add(jsonFileData);
        }
Пример #17
0
        private void SetRowDataForItem(RecipeRow row, string alias, JsonFileData jsonFileData)
        {
            JObject json = jsonFileData.Json;

            JToken appeal = json.SelectToken("entity_data.stonehearth:appeal.appeal");

            row.SetAppeal(appeal == null ? null : appeal.ToObject <int?>());

            JToken hasVariableItemQuality = json.SelectToken("entity_data.stonehearth:item_quality.variable_quality");

            row.SetIsVariableQuality(hasVariableItemQuality == null ? null : hasVariableItemQuality.ToObject <bool?>());

            JToken shopLevel = json.SelectToken("entity_data.stonehearth:net_worth.shop_info.shopkeeper_level");

            row.SetShopLvl(shopLevel == null ? null : shopLevel.ToObject <int?>());
            JToken isBuyable = json.SelectToken("entity_data.stonehearth:net_worth.shop_info.buyable");

            row.SetIsBuyable(isBuyable == null ? null : isBuyable.ToObject <bool?>());
            JToken isSellable = json.SelectToken("entity_data.stonehearth:net_worth.shop_info.sellable");

            row.SetIsSellable(isSellable == null ? null : isSellable.ToObject <bool?>());

            row.SetAlias(alias);

            row.Item = jsonFileData;
            row.SetNetWorth(jsonFileData.NetWorth == -1 ? (int?)null : (int?)jsonFileData.NetWorth);
            row.SetDisplayName(GetTranslatedName(GetDisplayName(jsonFileData)));
            row.SetCategory(GetCategoryName(jsonFileData));
            row.SetMaterialTags(GetMaterialTags(jsonFileData));
            row.SetIcon(GetIcon(jsonFileData));

            if (jsonFileData.GetModuleFile() != null && jsonFileData.GetModuleFile().IsDeprecated)
            {
                row.IsDeprecated = true;
            }
        }
Пример #18
0
 public Ingredient(RecipeRow row, IngredientColumnGroup columnGroup)
 {
     this.mRow         = row;
     this.mColumnGroup = columnGroup;
 }
Пример #19
0
 public override bool TryDeleteCell(RecipeRow row)
 {
     row.SetWorkUnits(null);
     return(true);
 }
Пример #20
0
 public override bool TryDeleteCell(RecipeRow row)
 {
     row.SetIsSellable(null);
     return(true);
 }
Пример #21
0
 public override bool TryDeleteCell(RecipeRow row)
 {
     row.SetShopLvl(null);
     return(true);
 }
Пример #22
0
 public override bool TryDeleteCell(RecipeRow row)
 {
     row.SetIsVariableQuality(null);
     return(true);
 }
Пример #23
0
 public virtual bool TryDeleteCell(RecipeRow row)
 {
     return(false);
 }
Пример #24
0
        private void LoadRecipesForJob(string jobAlias)
        {
            string modName           = jobAlias.Split(':')[0];
            int    index             = jobAlias.IndexOf(':');
            string jobKey            = jobAlias.Substring(index + 1);
            char   sep               = System.IO.Path.DirectorySeparatorChar;
            string recipeFileDataKey = modName + sep + "aliases" + sep + jobKey + sep + "recipes";

            JsonFileData recipesIndex = ModuleDataManager.GetInstance().GetSelectedFileData(recipeFileDataKey) as JsonFileData;

            // Non-crafter jobs will not have recipes
            if (recipesIndex == null)
            {
                return;
            }

            Dictionary <string, FileData> recipeFileData = recipesIndex.LinkedFileData;

            foreach (KeyValuePair <string, FileData> recipe in recipeFileData)
            {
                JsonFileData jsonFileData    = recipe.Value as JsonFileData;
                JObject      recipeJson      = jsonFileData.Json;
                JArray       ingredientArray = recipeJson["ingredients"] as JArray;
                JArray       productArray    = recipeJson["produces"] as JArray;

                foreach (JToken product in productArray)
                {
                    RecipeRow row = mDataTable.NewRecipeRow();

                    row.RecipeList = recipesIndex;
                    row.Recipe     = jsonFileData;

                    JToken lvlReq    = recipeJson["level_requirement"];
                    JToken effort    = recipeJson["effort"];
                    JToken workUnits = recipeJson["work_units"];
                    JToken appeal    = recipeJson.SelectToken("entity_data.stonehearth:appeal.appeal");

                    row.SetLevelRequired(lvlReq == null ? null : lvlReq.ToObject <int?>());
                    row.SetEffort(effort == null ? null : effort.ToObject <int?>());
                    row.SetWorkUnits(workUnits == null ? null : workUnits.ToObject <int?>());
                    row.SetCrafter(jobAlias);

                    JToken item = product["item"];
                    if (item != null)
                    {
                        string alias = item.ToString();
                        // Check aliases linked by recipe file
                        JsonFileData itemFileData = FindLinkedJsonMatchingAlias(jsonFileData, alias) ?? jsonFileData;
                        SetRowDataForItem(row, alias, itemFileData);
                    }

                    foreach (JToken ingredient in ingredientArray)
                    {
                        JToken uri      = ingredient["uri"];
                        JToken material = ingredient["material"];
                        JToken count    = ingredient["count"];

                        Ingredient ingredientData = row.AddNewIngredient();
                        ingredientData.Amount = count.ToObject <int>();

                        if (material != null)
                        {
                            ingredientData.Name = material.ToString();
                        }
                        else if (uri != null)
                        {
                            JsonFileData ingrJsonFileData = FindLinkedJsonMatchingAlias(jsonFileData, uri.ToString());
                            if (ingrJsonFileData == null)
                            {
                                MessageBox.Show("Could not find ingredient \"" + uri + "\" in the manifest for recipe \"" + jsonFileData.FileName + "\"");
                                continue;
                            }

                            ingredientData.Name = ingrJsonFileData.GetModuleFile().FullAlias;
                        }
                        else
                        {
                            throw new Exception("Recipe " + jsonFileData.GetModuleFile().FullAlias + " has invalid ingredient with no uri/material field");
                        }
                    }

                    mDataTable.Rows.Add(row);
                }
            }
        }
Пример #25
0
        private void recipesGridView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (!recipesGridView.IsCurrentCellInEditMode)
                {
                    recipesGridView.BeginEdit(true);
                    e.Handled = true;
                }
            }
            else if (e.Control && e.KeyCode == Keys.S)
            {
                // Save on ctrl+s
                SaveModifiedFiles();
            }
            else if ((e.Control && e.Shift && e.KeyCode == Keys.Z) || (e.Control && e.KeyCode == Keys.Y))
            {
                // Redo on ctrl+shift+z or ctrl+y
                ApplyCellChanges(mRedoStack, mUndoStack, changes => changes.Redo());
            }
            else if (e.Control && e.KeyCode == Keys.Z)
            {
                // Undo on ctrl+z
                ApplyCellChanges(mUndoStack, mRedoStack, changes => changes.Undo());
            }
            else if (e.KeyCode == Keys.Delete)
            {
                if (recipesGridView.SelectedCells.Count == 0)
                {
                    return;
                }
                else if (recipesGridView.SelectedCells.Count == 1)
                {
                    // Delete current cell on del if only one selected
                    DeleteCurrentCell();
                }
                else
                {
                    // Delete multiple cells
                    // Add cell changes to one transaction so we can roll back if needed
                    mIsApplyingChanges = true;
                    MultipleCellChange changes = new MultipleCellChange();

                    foreach (DataGridViewCell cell in recipesGridView.SelectedCells)
                    {
                        DataColumn dataColumn = mDataTable.GetColumn(cell.ColumnIndex);
                        RecipeRow  recipeRow  = mDataTable.GetRow(cell.RowIndex);

                        object oldValue = recipeRow[dataColumn];
                        object newValue = DBNull.Value;

                        bool success = mDataTable.GetColumnBehavior(dataColumn).TryDeleteCell(recipeRow);

                        if (!success)
                        {
                            changes.Undo();
                            return;
                        }

                        DataCell dataCell = new DataCell(dataColumn, recipeRow);
                        changes.Add(new CellChange(dataCell, oldValue, newValue));
                    }

                    // Save cell changes made in this delete operation
                    mUndoStack.Push(changes);
                    mIsApplyingChanges = false;
                }
            }
            else if (e.Control && e.KeyCode == Keys.V)
            {
                // Paste multiple cells on ctrl+v
                if (recipesGridView.SelectedCells.Count == 0)
                {
                    return;
                }

                // Add cell changes to one transaction so we can roll back if needed
                mIsApplyingChanges = true;
                MultipleCellChange changes = new MultipleCellChange();

                Tuple <DataGridViewCell, DataGridViewCell> boundaryCells = GetSelectedCellsBoundaries();
                DataGridViewCell startCell = boundaryCells.Item1;
                DataGridViewCell endCell   = boundaryCells.Item2;
                int startRow = startCell.RowIndex;
                int startCol = startCell.ColumnIndex;

                int      rowIndex  = startRow;
                string   s         = Clipboard.GetText();
                string[] lines     = s.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None);
                int      lineIndex = 0;
                while (lineIndex < lines.Count())
                {
                    string line = lines[lineIndex];
                    if (rowIndex < recipesGridView.Rows.Count)
                    {
                        string[] cells    = line.Split('\t');
                        int      colIndex = startCol;
                        for (int i = 0; i < cells.Length && colIndex < recipesGridView.Columns.Count; i++)
                        {
                            bool success = SetGridValue(colIndex, rowIndex, cells[i], changes);
                            if (!success)
                            {
                                changes.Undo();
                                return;
                            }

                            colIndex++;
                        }

                        rowIndex++;
                    }

                    lineIndex++;

                    // Repeat last line in clipboard if we've copied one line and the selected rows exceeds one line
                    if (lineIndex == lines.Count() && lines.Count() == 1)
                    {
                        int selectedRowCount  = Math.Abs(startCell.RowIndex - endCell.RowIndex) + 1;
                        int clipboardRowCount = Math.Abs((rowIndex - 1) - startRow) + 1;
                        if (selectedRowCount > clipboardRowCount)
                        {
                            lineIndex--;
                        }
                    }
                }

                // Save cell changes made in this paste operation
                mUndoStack.Push(changes);
                mIsApplyingChanges = false;
            }
        }
Пример #26
0
 public DataCell(DataColumn column, RecipeRow row)
 {
     this.Column = column;
     this.Row    = row;
 }
Пример #27
0
 public virtual void SaveCell(HashSet <JsonFileData> modifiedFiles, RecipeRow row, object value)
 {
 }