Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Prefabs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Source.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 66 additions & 8 deletions Source/Game/GameEvent.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using UnityEngine;
using System.Collections.Generic;
using System.Linq;

[System.Serializable]
public class GameEvent : ScriptableObject{
public class GameEvent : ScriptableObject, JSONAble{

void Awake(){
if (args == null || args.Count != keys.Count) {
Expand Down Expand Up @@ -33,11 +34,10 @@ public object getParameter(string param){

public void setParameter(string param, object content){
param = param.ToLower();
object c = content;
if(c is System.ValueType || c is string){
c = ScriptableObject.CreateInstance<IsoUnityBasicType>();
((IsoUnityBasicType)c).Value = content;
}
object c = IsoUnityTypeFactory.Instance.getIsoUnityType(content);
if (c == null)
c = content;

if(args.ContainsKey(param)) args[param] = (Object)c;
else args.Add(param, (Object)c);

Expand All @@ -47,8 +47,14 @@ public void setParameter(string param, object content){

public void removeParameter(string param){
param = param.ToLower();
if(args.ContainsKey(param))
args.Remove(param);
if (args.ContainsKey(param))
{
UnityEngine.Object v = args[param];
if (v is IsoUnityBasicType)
IsoUnityTypeFactory.Instance.Destroy(v as IsoUnityBasicType);

args.Remove(param);
}

this.keys = new List<string> (args.Keys);
this.values = new List<Object> (args.Values);
Expand Down Expand Up @@ -106,5 +112,57 @@ public override int GetHashCode ()
{
return !(ge1 == ge2);
}


public JSONObject toJSONObject()
{
JSONObject json = new JSONObject();
json.AddField("name", name);
JSONObject parameters = new JSONObject();
foreach (KeyValuePair<string, Object> entry in args)
{
if (entry.Value is JSONAble)
{
var jsonAble = entry.Value as JSONAble;
parameters.AddField(entry.Key, JSONSerializer.Serialize(jsonAble));
}
else
{
parameters.AddField(entry.Key, entry.Value.GetInstanceID());
}
}


json.AddField("parameters", parameters);
return json;
}

private static void destroyBasic(Dictionary<string, Object> args)
{
if (args == null || args.Count == 0)
return;

foreach (KeyValuePair<string, Object> entry in args)
if (entry.Value is IsoUnityBasicType)
IsoUnityBasicType.DestroyImmediate(entry.Value);
}

public void fromJSONObject(JSONObject json)
{
this.name = json["name"].ToString();

//Clean basic types
destroyBasic(this.args);

this.args = new Dictionary<string, Object>();

JSONObject parameters = json["parameters"];
foreach (string key in parameters.keys)
{
JSONObject param = parameters[key];
JSONAble unserialized = JSONSerializer.UnSerialize(param);
this.setParameter(key, unserialized);
}
}
}

53 changes: 0 additions & 53 deletions Source/Game/IsoUnityBasicType.cs

This file was deleted.

16 changes: 16 additions & 0 deletions Source/Game/IsoUnityType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using UnityEngine;
using System.Collections;

public abstract class IsoUnityType : ScriptableObject, JSONAble
{
public abstract bool canHandle(object o);
public abstract IsoUnityType clone();
public abstract object Value
{
get;
set;
}
public abstract JSONObject toJSONObject();

public abstract void fromJSONObject(JSONObject json);
}
12 changes: 12 additions & 0 deletions Source/Game/IsoUnityType.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions Source/Game/IsoUnityTypeFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using UnityEngine;
using System.Collections.Generic;

public abstract class IsoUnityTypeFactory
{
private static IsoUnityTypeFactory instance;
public static IsoUnityTypeFactory Instance
{
get
{
if (instance == null)
instance = new IsoUnityTypeFactoryImp();
return instance;
}
}
public abstract void Destroy(IsoUnityType i);
public abstract IsoUnityType getIsoUnityType(object c);

private class IsoUnityTypeFactoryImp : IsoUnityTypeFactory
{
private List<IsoUnityType> types;

public IsoUnityTypeFactoryImp()
{
types = new List<IsoUnityType>();
types.Add(ScriptableObject.CreateInstance<IsoUnityBasicType>());
types.Add(ScriptableObject.CreateInstance<IsoUnityCollectionType>());
}

public override void Destroy(IsoUnityType i)
{
IsoUnityType.DestroyImmediate(i);
}

public override IsoUnityType getIsoUnityType(object c)
{
IsoUnityType r = null;
foreach (IsoUnityType t in types)
{
if (t.canHandle(c))
{
r = t.clone();
r.Value = c;
break;
}
}
return r;
}
}

}
12 changes: 12 additions & 0 deletions Source/Game/IsoUnityTypeFactory.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Source/Game/IsoUnityTypes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading