Skip to content
Snippets Groups Projects
Commit f7adbc61 authored by Kenneth Ezekiel's avatar Kenneth Ezekiel
Browse files

Merge branch 'base_arch' into 'dev'

Statistics

See merge request !3
parents c0bf190d 3be95b24
1 merge request!3Statistics
Showing
with 225 additions and 9 deletions
......@@ -69,4 +69,6 @@ crashlytics-build.properties
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
\ No newline at end of file
/[Aa]ssets/[Ss]treamingAssets/aa/*
.idea
\ No newline at end of file
using System;
using System.Collections.Generic;
using UnityEngine;
namespace _Scripts.Core.Game.Data.Currency
{
public class CurrencyData
[Serializable]
public class CurrencyData: DataClass
{
public int Balance = 0;
[Serializable]
public class Transaction
{
public int amount;
public String description;
}
// public List<Transaction> = TransactionHistory;
public int balance;
public List<Transaction> transactions = new();
public void AddTransaction(int amount, string description)
{
transactions.Add(new Transaction { amount = amount, description = description });
balance += amount;
}
public override void Load(string json)
{
CurrencyData data = JsonUtility.FromJson<CurrencyData>(json);
if (data != null)
{
transactions.Clear();
if (data.transactions != null)
{
foreach (Transaction transaction in data.transactions)
{
transactions.Add(new Transaction { amount = transaction.amount, description = transaction.description });
}
}
balance = data.balance;
}
}
public override string SaveToJson()
{
return JsonUtility.ToJson(this);
}
}
}
\ No newline at end of file
namespace _Scripts.Core.Game.Data
{
public abstract class DataClass
{
public abstract void Load(string json);
public abstract string SaveToJson();
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 1409dd2bfcd949c9b9ac094b146df878
timeCreated: 1713927410
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using _Scripts.Core.Game.Data.Currency;
using _Scripts.Core.Game.Data.Position;
using _Scripts.Core.Game.Data.Statistics;
using _Scripts.Core.Game.Data.Story;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Serialization;
public class GameSaveData : MonoBehaviour
public class GameSaveData : MonoBehaviour
{
// Static Instance
public static GameSaveData Instance;
// Attributes
public DifficultyType difficulty = DifficultyType.NORMAL;
public List<String> events = new();
// Save the currency of the player
// Save the story state of the player
public CurrencyData currencyData = new();
// Save the position and the level of the player
public PositionData positionData = new();
// Save the story state of the player
public StoryData storyData;
public StatisticsData statisticsData = new();
// Constructor
private void Awake()
{
Instance = this;
storyData = new StoryData(events);
DontDestroyOnLoad(gameObject);
}
public void SaveGame()
{
GameDataWrapper wrapper = new GameDataWrapper
{
difficulty = this.difficulty,
events = this.events,
currencyData = this.currencyData,
positionData = this.positionData,
storyData = this.storyData,
statisticsData = this.statisticsData
};
string json = JsonUtility.ToJson(wrapper, true);
File.WriteAllText(Application.persistentDataPath + "/savegame.json", json);
Debug.Log("Game saved to " + Application.persistentDataPath + "/savegame.json");
}
public void LoadGame()
{
string path = Application.persistentDataPath + "/savegame.json";
if (File.Exists(path))
{
string json = File.ReadAllText(path);
GameDataWrapper wrapper = JsonUtility.FromJson<GameDataWrapper>(json);
this.difficulty = wrapper.difficulty;
this.events = wrapper.events;
this.currencyData = wrapper.currencyData;
this.positionData = wrapper.positionData;
this.storyData = wrapper.storyData;
this.statisticsData = wrapper.statisticsData;
Debug.Log("Game loaded from " + path);
}
else
{
Debug.LogError("Save file not found in " + path);
}
}
}
[Serializable]
public class GameDataWrapper
{
public DifficultyType difficulty;
public List<String> events;
public CurrencyData currencyData;
public PositionData positionData;
public StoryData storyData;
public StatisticsData statisticsData;
}
fileFormatVersion: 2
guid: c180590641784f4dbcbfa7b82df76b14
timeCreated: 1713925100
\ No newline at end of file
using System;
using UnityEngine;
namespace _Scripts.Core.Game.Data.Position
{
[Serializable]
public class PositionData: DataClass
{
public int level = 1;
public Vector3 point = new(0, 0, 0);
public override void Load(string json)
{
PositionData data = JsonUtility.FromJson<PositionData>(json);
if (data != null)
{
level = data.level;
point = data.point;
}
}
public override string SaveToJson()
{
return JsonUtility.ToJson(this);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 21e6e7f20e444735970bf93c4711fd4d
timeCreated: 1713925119
\ No newline at end of file
fileFormatVersion: 2
guid: 4479f1739fe8476aa8170ea9ad5a7feb
timeCreated: 1713929215
\ No newline at end of file
using System;
using UnityEngine;
namespace _Scripts.Core.Game.Data.Statistics
{
[Serializable]
public class StatisticsData: DataClass
{
public int enemiesKilled = 0;
public override void Load(string json)
{
StatisticsData data = JsonUtility.FromJson<StatisticsData>(json);
if (data != null)
{
enemiesKilled = data.enemiesKilled;
}
}
public override string SaveToJson()
{
return JsonUtility.ToJson(this);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 699af7536f1e4c5584c4d74309a3eea3
timeCreated: 1713929223
\ No newline at end of file
using System;
using System.Collections.Generic;
using UnityEditor.PackageManager;
using UnityEngine;
namespace _Scripts.Core.Game.Data.Story
{
public class StoryData
[Serializable]
public class StoryData: DataClass
{
public List<int> List;
public List<String> events = new();
public List<Boolean> progress = new();
public StoryData(List<String> eventsList)
{
foreach (string eventId in eventsList)
{
events.Add(eventId);
progress.Add(false);
}
}
public void CompleteEvent(String eventId)
{
int idx = events.FindIndex(0, e => e == eventId);
progress[idx] = true;
}
public override void Load(string json)
{
StoryData data = JsonUtility.FromJson<StoryData>(json);
if (data != null)
{
events = data.events;
progress = data.progress;
}
}
public override string SaveToJson()
{
return JsonUtility.ToJson(this);
}
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment