public void SaveGame() { GameStateData gsd = new GameStateData(); //put all tree data into an array of FruitTreeData GameObject [] trees = GameObject.FindGameObjectsWithTag("Tree"); FruitTreeData[] treeData = new FruitTreeData[trees.Length]; for (int i = 0; i < treeData.Length; i++) { treeData[i] = trees[i].GetComponent <FruitTree>().Serialize(); } //create a new GameStateData gsd.trees = treeData; ItemSelector item = GameObject.FindGameObjectWithTag("Inventory").GetComponent <ItemSelector>(); //fill in da blanks gsd.seedCount = item.numSeeds; gsd.fruitCount = item.numFruit; gsd.playerEnergy = transform.GetComponent <DirectionalMovement>().energy; gsd.playerPos = transform.parent.position; gsd.playerRot = Camera.main.transform.rotation; DayCycle day = GameObject.FindGameObjectWithTag("Sun").GetComponent <DayCycle>(); gsd.seasonCode = day.seasonCode; gsd.dayCode = day.dayCode; //serialize GameStateData to json string path = Application.persistentDataPath + "/saveData.json"; //write json string to file in persistantDataPath File.WriteAllText(path, JsonUtility.ToJson(gsd)); Debug.Log("Save success"); }
public void Deserialize(FruitTreeData mData) { transform.localScale = mData.myScale; breakTime = mData.breakTime; branchTime = mData.branchTime; trunkAxisRandom = mData.trunkAxisRandom; branchAxisRandom = mData.branchAxisRandom; branchRate = mData.branchRate; growthRateDelay = mData.growthRateDelay; branchScaleVector = mData.branchScaleVector; branchGrowthScale = mData.branchGrowthScale; globalGrowthRate = mData.globalGrowthRate; alive = mData.alive; growing = mData.growing; fruiting = mData.fruiting; hasTrunk = mData.hasTrunk; oldBranchPositions = mData.liveBranchPositions; oldBranchRotations = mData.liveBranchRotations; allBranchPositions = mData.allBranchPositions; allBranchRotations = mData.allBranchRotations; allBranchScales = mData.allBranchScales; maxBranchLevel = mData.maxBranchLevel; fruitPeriod = mData.fruitPeriod; hasLeaves = mData.hasLeaves; loaded = true; }
public FruitTreeData Serialize() { FruitTreeData mData = new FruitTreeData(); mData.myPos = transform.position; mData.myScale = transform.localScale; mData.branchType = 0; //use this later when we have different types of branches mData.breakTime = breakTime; mData.branchTime = branchTime; mData.trunkAxisRandom = trunkAxisRandom; mData.branchAxisRandom = branchAxisRandom; mData.branchRate = branchRate; mData.growthRateDelay = growthRateDelay; mData.branchScaleVector = branchScaleVector; mData.branchGrowthScale = branchGrowthScale; mData.globalGrowthRate = globalGrowthRate; mData.alive = alive; mData.growing = growing; mData.fruiting = fruiting; mData.hasTrunk = hasTrunk; mData.liveBranchPositions = liveBranchPositions; mData.liveBranchRotations = liveBranchRotations; mData.allBranchPositions = allBranchPositions; mData.allBranchRotations = allBranchRotations; mData.allBranchScales = allBranchScales; mData.maxBranchLevel = maxBranchLevel; mData.fruitPeriod = fruitPeriod; mData.hasLeaves = hasLeaves; return(mData); }
private void DoFruitTreesEditorConnections(Node editor, TreeItem entry) { activeTree = trees[entry]; DoEditorConnections(editor, activeTree); var intEdit = editor.GetNode <SpinBox>("Texture/SubImageEditor/Values/SubRectWidth/SpinBox"); intEdit.Value = 432; intEdit.Editable = false; intEdit = editor.GetNode <SpinBox>("Texture/SubImageEditor/Values/SubRectHeight/SpinBox"); intEdit.Value = 80; intEdit.Editable = false; intEdit = editor.GetNode <SpinBox>("SaplingTexture/SubImageEditor/Values/SubRectWidth/SpinBox"); intEdit.Value = 16; intEdit.Editable = false; intEdit = editor.GetNode <SpinBox>("SaplingTexture/SubImageEditor/Values/SubRectHeight/SpinBox"); intEdit.Value = 16; intEdit.Editable = false; }
private void loadData(IContentPack contentPack) { Log.info($"\t{contentPack.Manifest.Name} {contentPack.Manifest.Version} by {contentPack.Manifest.Author} - {contentPack.Manifest.Description}"); // load objects DirectoryInfo objectsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Objects")); if (objectsDir.Exists) { foreach (DirectoryInfo dir in objectsDir.EnumerateDirectories()) { string relativePath = $"Objects/{dir.Name}"; // load data ObjectData obj = contentPack.ReadJsonFile <ObjectData>($"{relativePath}/object.json"); if (obj == null) { continue; } // save object obj.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/object.png"); if (obj.IsColored) { obj.textureColor = contentPack.LoadAsset <Texture2D>($"{relativePath}/color.png"); } this.objects.Add(obj); // save ring if (obj.Category == ObjectData.Category_.Ring) { this.myRings.Add(obj); } } } // load crops DirectoryInfo cropsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Crops")); if (cropsDir.Exists) { foreach (DirectoryInfo dir in cropsDir.EnumerateDirectories()) { string relativePath = $"Crops/{dir.Name}"; // load data CropData crop = contentPack.ReadJsonFile <CropData>($"{relativePath}/crop.json"); if (crop == null) { continue; } // save crop crop.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/crop.png"); crops.Add(crop); // save seeds crop.seed = new ObjectData { texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/seeds.png"), Name = crop.SeedName, Description = crop.SeedDescription, Category = ObjectData.Category_.Seeds, Price = crop.SeedPurchasePrice, CanPurchase = true, PurchaseFrom = crop.SeedPurchaseFrom, PurchasePrice = crop.SeedPurchasePrice, PurchaseRequirements = crop.SeedPurchaseRequirements ?? new List <string>() }; // TODO: Clean up this chunk // I copy/pasted it from the unofficial update decompiled string str = ""; string[] array = new string[] { "spring", "summer", "fall", "winter" }.Except(crop.Seasons).ToArray <string>(); for (int i = 0; i < array.Length; i++) { string season = array[i]; str += string.Format("/z {0}", season); } string strtrimstart = str.TrimStart(new char[] { '/' }); if (crop.SeedPurchaseRequirements != null && crop.SeedPurchaseRequirements.Count > 0) { for (int index = 0; index < crop.SeedPurchaseRequirements.Count; index++) { if (SeasonLimiter.IsMatch(crop.SeedPurchaseRequirements[index])) { crop.SeedPurchaseRequirements[index] = strtrimstart; Log.warn(string.Format(" Faulty season requirements for {0}!\n", crop.SeedName) + string.Format(" Fixed season requirements: {0}", crop.SeedPurchaseRequirements[index])); } } if (!crop.SeedPurchaseRequirements.Contains(str.TrimStart(new char[] { '/' }))) { Log.trace(string.Format(" Adding season requirements for {0}:\n", crop.SeedName) + string.Format(" New season requirements: {0}", strtrimstart)); crop.seed.PurchaseRequirements.Add(strtrimstart); } } else { Log.trace(string.Format(" Adding season requirements for {0}:\n", crop.SeedName) + string.Format(" New season requirements: {0}", strtrimstart)); crop.seed.PurchaseRequirements.Add(strtrimstart); } objects.Add(crop.seed); } } // load fruit trees DirectoryInfo fruitTreesDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "FruitTrees")); if (fruitTreesDir.Exists) { foreach (DirectoryInfo dir in fruitTreesDir.EnumerateDirectories()) { string relativePath = $"FruitTrees/{dir.Name}"; // load data FruitTreeData tree = contentPack.ReadJsonFile <FruitTreeData>($"{relativePath}/tree.json"); if (tree == null) { continue; } // save fruit tree tree.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/tree.png"); fruitTrees.Add(tree); // save seed tree.sapling = new ObjectData { texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/sapling.png"), Name = tree.SaplingName, Description = tree.SaplingDescription, Category = ObjectData.Category_.Seeds, Price = tree.SaplingPurchasePrice, CanPurchase = true, PurchaseRequirements = tree.SaplingPurchaseRequirements, PurchaseFrom = tree.SaplingPurchaseFrom, PurchasePrice = tree.SaplingPurchasePrice }; objects.Add(tree.sapling); } } // load big craftables DirectoryInfo bigCraftablesDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "BigCraftables")); if (bigCraftablesDir.Exists) { foreach (DirectoryInfo dir in bigCraftablesDir.EnumerateDirectories()) { string relativePath = $"BigCraftables/{dir.Name}"; // load data BigCraftableData craftable = contentPack.ReadJsonFile <BigCraftableData>($"{relativePath}/big-craftable.json"); if (craftable == null) { continue; } // save craftable craftable.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/big-craftable.png"); bigCraftables.Add(craftable); } } // load objects DirectoryInfo hatsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Hats")); if (hatsDir.Exists) { foreach (DirectoryInfo dir in hatsDir.EnumerateDirectories()) { string relativePath = $"Hats/{dir.Name}"; // load data HatData hat = contentPack.ReadJsonFile <HatData>($"{relativePath}/hat.json"); if (hat == null) { continue; } // save object hat.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/hat.png"); hats.Add(hat); } } }
private void loadData(IContentPack contentPack) { Log.info($"\t{contentPack.Manifest.Name} {contentPack.Manifest.Version} by {contentPack.Manifest.Author} - {contentPack.Manifest.Description}"); // load objects DirectoryInfo objectsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Objects")); if (objectsDir.Exists) { foreach (DirectoryInfo dir in objectsDir.EnumerateDirectories()) { string relativePath = $"Objects/{dir.Name}"; // load data ObjectData obj = contentPack.ReadJsonFile <ObjectData>($"{relativePath}/object.json"); if (obj == null) { continue; } // save object obj.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/object.png"); if (obj.IsColored) { obj.textureColor = contentPack.LoadAsset <Texture2D>($"{relativePath}/color.png"); } this.objects.Add(obj); // save ring if (obj.Category == ObjectData.Category_.Ring) { this.myRings.Add(obj); } // Duplicate check if (dupObjects.ContainsKey(obj.Name)) { Log.error($"Duplicate object: {obj.Name} just added by {contentPack.Manifest.Name}, already added by {dupObjects[obj.Name].Manifest.Name}!"); } else { dupObjects[obj.Name] = contentPack; } } } // load crops DirectoryInfo cropsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Crops")); if (cropsDir.Exists) { foreach (DirectoryInfo dir in cropsDir.EnumerateDirectories()) { string relativePath = $"Crops/{dir.Name}"; // load data CropData crop = contentPack.ReadJsonFile <CropData>($"{relativePath}/crop.json"); if (crop == null) { continue; } // save crop crop.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/crop.png"); crops.Add(crop); // save seeds crop.seed = new ObjectData { texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/seeds.png"), Name = crop.SeedName, Description = crop.SeedDescription, Category = ObjectData.Category_.Seeds, Price = crop.SeedPurchasePrice, CanPurchase = true, PurchaseFrom = crop.SeedPurchaseFrom, PurchasePrice = crop.SeedPurchasePrice, PurchaseRequirements = crop.SeedPurchaseRequirements ?? new List <string>(), NameLocalization = crop.SeedNameLocalization, DescriptionLocalization = crop.SeedDescriptionLocalization }; // TODO: Clean up this chunk // I copy/pasted it from the unofficial update decompiled string str = ""; string[] array = new[] { "spring", "summer", "fall", "winter" } .Except(crop.Seasons) .ToArray(); foreach (var season in array) { str += $"/z {season}"; } string strtrimstart = str.TrimStart(new char[] { '/' }); if (crop.SeedPurchaseRequirements != null && crop.SeedPurchaseRequirements.Count > 0) { for (int index = 0; index < crop.SeedPurchaseRequirements.Count; index++) { if (SeasonLimiter.IsMatch(crop.SeedPurchaseRequirements[index])) { crop.SeedPurchaseRequirements[index] = strtrimstart; Log.warn($" Faulty season requirements for {crop.SeedName}!\n Fixed season requirements: {crop.SeedPurchaseRequirements[index]}"); } } if (!crop.SeedPurchaseRequirements.Contains(str.TrimStart('/'))) { Log.trace($" Adding season requirements for {crop.SeedName}:\n New season requirements: {strtrimstart}"); crop.seed.PurchaseRequirements.Add(strtrimstart); } } else { Log.trace($" Adding season requirements for {crop.SeedName}:\n New season requirements: {strtrimstart}"); crop.seed.PurchaseRequirements.Add(strtrimstart); } objects.Add(crop.seed); // Duplicate check if (dupCrops.ContainsKey(crop.Name)) { Log.error($"Duplicate crop: {crop.Name} just added by {contentPack.Manifest.Name}, already added by {dupCrops[crop.Name].Manifest.Name}!"); } else { dupCrops[crop.Name] = contentPack; } } } // load fruit trees DirectoryInfo fruitTreesDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "FruitTrees")); if (fruitTreesDir.Exists) { foreach (DirectoryInfo dir in fruitTreesDir.EnumerateDirectories()) { string relativePath = $"FruitTrees/{dir.Name}"; // load data FruitTreeData tree = contentPack.ReadJsonFile <FruitTreeData>($"{relativePath}/tree.json"); if (tree == null) { continue; } // save fruit tree tree.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/tree.png"); fruitTrees.Add(tree); // save seed tree.sapling = new ObjectData { texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/sapling.png"), Name = tree.SaplingName, Description = tree.SaplingDescription, Category = ObjectData.Category_.Seeds, Price = tree.SaplingPurchasePrice, CanPurchase = true, PurchaseRequirements = tree.SaplingPurchaseRequirements, PurchaseFrom = tree.SaplingPurchaseFrom, PurchasePrice = tree.SaplingPurchasePrice, NameLocalization = tree.SaplingNameLocalization, DescriptionLocalization = tree.SaplingDescriptionLocalization }; objects.Add(tree.sapling); // Duplicate check if (dupFruitTrees.ContainsKey(tree.Name)) { Log.error($"Duplicate fruit tree: {tree.Name} just added by {contentPack.Manifest.Name}, already added by {dupFruitTrees[tree.Name].Manifest.Name}!"); } else { dupFruitTrees[tree.Name] = contentPack; } } } // load big craftables DirectoryInfo bigCraftablesDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "BigCraftables")); if (bigCraftablesDir.Exists) { foreach (DirectoryInfo dir in bigCraftablesDir.EnumerateDirectories()) { string relativePath = $"BigCraftables/{dir.Name}"; // load data BigCraftableData craftable = contentPack.ReadJsonFile <BigCraftableData>($"{relativePath}/big-craftable.json"); if (craftable == null) { continue; } // save craftable craftable.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/big-craftable.png"); bigCraftables.Add(craftable); // Duplicate check if (dupBigCraftables.ContainsKey(craftable.Name)) { Log.error($"Duplicate big craftable: {craftable.Name} just added by {contentPack.Manifest.Name}, already added by {dupBigCraftables[craftable.Name].Manifest.Name}!"); } else { dupBigCraftables[craftable.Name] = contentPack; } } } // load hats DirectoryInfo hatsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Hats")); if (hatsDir.Exists) { foreach (DirectoryInfo dir in hatsDir.EnumerateDirectories()) { string relativePath = $"Hats/{dir.Name}"; // load data HatData hat = contentPack.ReadJsonFile <HatData>($"{relativePath}/hat.json"); if (hat == null) { continue; } // save object hat.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/hat.png"); hats.Add(hat); // Duplicate check if (dupHats.ContainsKey(hat.Name)) { Log.error($"Duplicate hat: {hat.Name} just added by {contentPack.Manifest.Name}, already added by {dupHats[hat.Name].Manifest.Name}!"); } else { dupBigCraftables[hat.Name] = contentPack; } } } // Load weapons // load objects DirectoryInfo weaponsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Weapons")); if (weaponsDir.Exists) { foreach (DirectoryInfo dir in weaponsDir.EnumerateDirectories()) { string relativePath = $"Weapons/{dir.Name}"; // load data WeaponData weapon = contentPack.ReadJsonFile <WeaponData>($"{relativePath}/weapon.json"); if (weapon == null) { continue; } // save object weapon.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/weapon.png"); weapons.Add(weapon); // Duplicate check if (dupWeapons.ContainsKey(weapon.Name)) { Log.error($"Duplicate weapon: {weapon.Name} just added by {contentPack.Manifest.Name}, already added by {dupWeapons[weapon.Name].Manifest.Name}!"); } else { dupBigCraftables[weapon.Name] = contentPack; } } } }
private void loadData(IContentPack contentPack) { Log.info($"\t{contentPack.Manifest.Name} {contentPack.Manifest.Version} by {contentPack.Manifest.Author} - {contentPack.Manifest.Description}"); // load objects DirectoryInfo objectsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Objects")); if (objectsDir.Exists) { foreach (DirectoryInfo dir in objectsDir.EnumerateDirectories()) { string relativePath = $"Objects/{dir.Name}"; // load data ObjectData obj = contentPack.ReadJsonFile <ObjectData>($"{relativePath}/object.json"); if (obj == null) { continue; } // save object obj.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/object.png"); if (obj.IsColored) { obj.textureColor = contentPack.LoadAsset <Texture2D>($"{relativePath}/color.png"); } this.objects.Add(obj); // save ring if (obj.Category == ObjectData.Category_.Ring) { this.myRings.Add(obj); } } } // load crops DirectoryInfo cropsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Crops")); if (cropsDir.Exists) { foreach (DirectoryInfo dir in cropsDir.EnumerateDirectories()) { string relativePath = $"Crops/{dir.Name}"; // load data CropData crop = contentPack.ReadJsonFile <CropData>($"{relativePath}/crop.json"); if (crop == null) { continue; } // save crop crop.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/crop.png"); crops.Add(crop); // save seeds crop.seed = new ObjectData { texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/seeds.png"), Name = crop.SeedName, Description = crop.SeedDescription, Category = ObjectData.Category_.Seeds, Price = crop.SeedPurchasePrice, CanPurchase = true, PurchaseFrom = crop.SeedPurchaseFrom, PurchasePrice = crop.SeedPurchasePrice, PurchaseRequirements = crop.SeedPurchaseRequirements ?? new List <string>() }; string[] excludeSeasons = new[] { "spring", "summer", "fall", "winter" }.Except(crop.Seasons).ToArray(); crop.seed.PurchaseRequirements.Add($"z {string.Join(" ", excludeSeasons)}"); objects.Add(crop.seed); } } // load fruit trees DirectoryInfo fruitTreesDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "FruitTrees")); if (fruitTreesDir.Exists) { foreach (DirectoryInfo dir in fruitTreesDir.EnumerateDirectories()) { string relativePath = $"FruitTrees/{dir.Name}"; // load data FruitTreeData tree = contentPack.ReadJsonFile <FruitTreeData>($"{relativePath}/tree.json"); if (tree == null) { continue; } // save fruit tree tree.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/tree.png"); fruitTrees.Add(tree); // save seed tree.sapling = new ObjectData { texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/sapling.png"), Name = tree.SaplingName, Description = tree.SaplingDescription, Category = ObjectData.Category_.Seeds, Price = tree.SaplingPurchasePrice, CanPurchase = true, PurchaseRequirements = tree.SaplingPurchaseRequirements, PurchaseFrom = tree.SaplingPurchaseFrom, PurchasePrice = tree.SaplingPurchasePrice }; objects.Add(tree.sapling); } } // load big craftables DirectoryInfo bigCraftablesDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "BigCraftables")); if (bigCraftablesDir.Exists) { foreach (DirectoryInfo dir in bigCraftablesDir.EnumerateDirectories()) { string relativePath = $"BigCraftables/{dir.Name}"; // load data BigCraftableData craftable = contentPack.ReadJsonFile <BigCraftableData>($"{relativePath}/big-craftable.json"); if (craftable == null) { continue; } // save craftable craftable.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/big-craftable.png"); bigCraftables.Add(craftable); } } // load objects DirectoryInfo hatsDir = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Hats")); if (hatsDir.Exists) { foreach (DirectoryInfo dir in hatsDir.EnumerateDirectories()) { string relativePath = $"Hats/{dir.Name}"; // load data HatData hat = contentPack.ReadJsonFile <HatData>($"{relativePath}/hat.json"); if (hat == null) { continue; } // save object hat.texture = contentPack.LoadAsset <Texture2D>($"{relativePath}/hat.png"); hats.Add(hat); } } }