Example #1
0
 public static Var ToVar(VarScope vs, string value)
 {
     if (vs != null)
     {
         string varname = GetVarName(value);
         if (varname != null)
         {
             return(vs[varname]);
         }
     }
     return(new Var(value));
 }
Example #2
0
 public static string ToText(VarScope vs, string value)
 {
     if (vs != null)
     {
         string varname = GetVarName(value);
         if (varname != null)
         {
             return((string)vs[varname]);
         }
     }
     return(value);
 }
Example #3
0
        public static Vector3 ToVector(VarScope vs, string value)
        {
            Vector3 retval;

            if (vs != null)
            {
                string varname = GetVarName(value);
                if (varname != null)
                {
                    value = vs[varname].data;
                }
            }
            if (SEType.TryParse_VECTOR(value, out retval))
            {
                return(retval);
            }
            return(Vector3.zero);
        }
Example #4
0
        public static int ToInt(VarScope vs, string value)
        {
            int retval = 0;

            if (vs != null)
            {
                string varname = GetVarName(value);
                if (varname != null)
                {
                    return((int)(vs[varname]));
                }
            }
            if (int.TryParse(value, out retval))
            {
                return(retval);
            }
            return(0);
        }
Example #5
0
        public static DIRRANGE ToDirRange(VarScope vs, string value)
        {
            DIRRANGE retval;

            if (vs != null)
            {
                string varname = GetVarName(value);
                if (varname != null)
                {
                    value = vs[varname].data;
                }
            }

            if (SEType.TryParse_DIRRANGE(value, out retval))
            {
                return(retval);
            }
            return(DIRRANGE.nodir);
        }
Example #6
0
        public static RANGE ToRange(VarScope vs, string value)
        {
            RANGE retval;

            if (vs != null)
            {
                string varname = GetVarName(value);
                if (varname != null)
                {
                    value = vs[varname].data;
                }
            }

            if (SEType.TryParse_RANGE(value, out retval))
            {
                return(retval);
            }
            return(RANGE.nowhere);
        }
Example #7
0
        public static Color ToColor(VarScope vs, string value)
        {
            Color32 retval;

            if (vs != null)
            {
                string varname = GetVarName(value);
                if (varname != null)
                {
                    value = vs[varname].data;
                }
            }

            if (SEType.TryParse_COLOR(value, out retval))
            {
                return((Color)retval);
            }
            return(Color.white);
        }
Example #8
0
        public static Rect ToRect(VarScope vs, string value)
        {
            Rect retval;

            if (vs != null)
            {
                string varname = GetVarName(value);
                if (varname != null)
                {
                    value = vs[varname].data;
                }
            }

            if (SEType.TryParse_RECT(value, out retval))
            {
                return(retval);
            }
            return(new Rect(0, 0, 0, 0));
        }
Example #9
0
        public static double ToDouble(VarScope vs, string value)
        {
            double retval = 0;

            if (vs != null)
            {
                string varname = GetVarName(value);
                if (varname != null)
                {
                    return((double)(vs[varname]));
                }
            }
            if (double.TryParse(value, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite |
                                NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint |
                                NumberStyles.AllowExponent, NumberFormatInfo.CurrentInfo, out retval))
            {
                return(retval);
            }
            return(0);
        }
Example #10
0
        public static bool ToBool(VarScope vs, string value)
        {
            int retval = 0;

            if (vs != null)
            {
                string varname = GetVarName(value);
                if (varname != null)
                {
                    return((bool)(vs[varname]));
                }
            }
            if (int.TryParse(value, out retval))
            {
                return(retval != 0);
            }
            if (value.ToLower() == "true")
            {
                return(true);
            }
            return(false);
        }
Example #11
0
        /// <summary>Restore the scenario data from a opening stream</summary>
        public void Import(BinaryReader r)
        {
            int version = r.ReadInt32();

            switch (version)
            {
            case 0x00000001:
            {
                m_Pause = true;
                int count = r.ReadInt32();
                m_MaxMissionId = 0;
                for (int i = 0; i < count; i++)
                {
                    int  instId  = r.ReadInt32();
                    int  dataId  = r.ReadInt32();
                    bool enabled = r.ReadBoolean();

                    if (!m_MissionRaws.ContainsKey(dataId))
                    {
                        throw new System.Exception("Mission raw data of id [" + dataId.ToString() + "] is missing");
                    }

                    Mission mis = new Mission(instId, m_MissionRaws[dataId], this);
                    mis.Init();

                    int trg_cnt = r.ReadInt32();

                    if (trg_cnt != mis.triggers.Length)
                    {
                        throw new System.Exception("Trigger count is not correct");
                    }

                    for (int j = 0; j < trg_cnt; j++)
                    {
                        mis.triggers[j].Import(r);
                    }

                    VarScope vs = Variables.CreateChild();
                    vs.Import(r);
                    MissionVariables[mis] = vs;

                    m_MissionInsts.Add(instId, mis);
                    if (enabled)
                    {
                        //mis.Resume();
                        m_RunningMissions.Add(dataId, mis);
                    }

                    if (instId > m_MaxMissionId)
                    {
                        m_MaxMissionId = instId;
                    }
                }

                Variables.Import(r);

                // restore action thread
                count = r.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    int instId      = r.ReadInt32();
                    int dataId      = r.ReadInt32();
                    int trigger_idx = r.ReadInt32();
                    int group       = r.ReadInt32();
                    int cur_idx     = r.ReadInt32();

                    if (!m_MissionRaws.ContainsKey(dataId))
                    {
                        throw new System.Exception("Mission raw data of id [" + dataId.ToString() + "] is missing");
                    }

                    if (!m_MissionInsts.ContainsKey(instId))
                    {
                        throw new System.Exception("Mission instance of instId [" + dataId.ToString() + "] is missing");
                    }


                    MissionRaw   mis_raw = m_MissionRaws[dataId];
                    ActionThread thread  = null;
                    Mission      mis     = m_MissionInsts[instId];
                    mis.triggers[trigger_idx].FillActionCache(group);

                    thread = new ActionThread(mis.triggers[trigger_idx], trigger_idx, group,
                                              mis_raw.triggers[trigger_idx].actions[group], mis.triggers[trigger_idx].GetActionCache(group), cur_idx);

                    mis.triggers[trigger_idx].RegisterActionThreadEvent(thread);

                    AddActionThread(thread);

                    thread.CreateCurrAction();
                    if (thread.currAction != null)
                    {
                        thread.currAction.RestoreState(r);
                    }
                }
            }
            break;
            }
        }
Example #12
0
 private VarScope(VarScope parent_scope)
 {
     m_ParentScope = parent_scope;
     m_Vars        = new Dictionary <string, Var>();
 }
Example #13
0
 public VarScope()
 {
     m_ParentScope = null;
     m_Vars        = new Dictionary <string, Var>();
 }