Beispiel #1
0
 static public object[] Load(string fileName,
                             Type clazz)
 {
     object[] obj = null;
     try
     {
         CSVTable.CSVItem[] properts = Load(fileName);
         if (properts != null)
         {
             int size = properts.Length - 1;
             obj = (object[])Arrays.NewInstance(clazz, size);
             for (int i = 0; i < size; i++)
             {
                 CSVTable.CSVItem property = properts[i];
                 if (property != null)
                 {
                     ArrayMap.Entry[] entry = property.ToEntrys();
                     obj[i] = Activator.CreateInstance(clazz);
                     for (int j = 0; j < entry.Length; j++)
                     {
                         ArrayMap.Entry e = entry[j];
                         Register(obj[i], (string)e.GetKey(),
                                  (string)e.GetValue());
                     }
                 }
             }
             properts = null;
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex + " " + fileName);
     }
     return(obj);
 }
Beispiel #2
0
 public IList GetObjects(Type cls)
 {
     lock (typeof(CollisionManager)) {
         IList            result  = this.collisionChecker.GetObjects(cls);
         ArrayMap.Entry[] entries = this.freeObjects.ToEntrys();
         for (int i = 0; i < entries.Length; i++)
         {
             ArrayMap.Entry entry = entries[i];
             if (cls == null || cls.IsAssignableFrom((Type)entry.GetKey()))
             {
                 CollectionUtils.AddAll((ICollection)entry.GetValue(), result);
             }
         }
         return(result);
     }
 }
Beispiel #3
0
 public void StopSoundAll()
 {
     if (sounds != null)
     {
         List <ArrayMap.Entry> list = sounds.ToList();
         for (int i = 0; i < list.Count; i++)
         {
             ArrayMap.Entry sound = list[i];
             if (sound != null)
             {
                 AudioEffect ass = (AudioEffect)sound.GetValue();
                 if (ass != null)
                 {
                     ass.StopAudioEffect();
                 }
             }
         }
     }
 }
Beispiel #4
0
        private void Parse(Stream file)
        {
            if (displays == null)
            {
                displays = new ArrayMap(DEFAULT_MAX_CHAR);
            }
            else
            {
                displays.Clear();
            }
            try {
                StreamReader ins = new StreamReader(file,
                                                    System.Text.Encoding.UTF8);
                info   = ins.ReadLine();
                common = ins.ReadLine();
                page   = ins.ReadLine();

                ArrayMap kerning = new ArrayMap(
                    64);
                List <CharDef> charDefs = new List <CharDef>(
                    DEFAULT_MAX_CHAR);

                int  maxChar = 0;
                bool done    = false;
                for (; !done;)
                {
                    string line = ins.ReadLine();
                    if (line == null)
                    {
                        done = true;
                    }
                    else
                    {
                        if (line.StartsWith("chars c"))
                        {
                        }
                        else if (line.StartsWith("char"))
                        {
                            CharDef def = ParseChar(line);
                            if (def != null)
                            {
                                maxChar = MathUtils.Max(maxChar, def.id);
                                charDefs.Add(def);
                            }
                        }
                        if (line.StartsWith("kernings c"))
                        {
                        }
                        else if (line.StartsWith("kerning"))
                        {
                            StringTokenizer tokens = new StringTokenizer(line, " =");
                            tokens.NextToken();
                            tokens.NextToken();
                            short first = short.Parse(tokens.NextToken());
                            tokens.NextToken();
                            int second = int.Parse(tokens.NextToken());
                            tokens.NextToken();
                            int          offset = int.Parse(tokens.NextToken());
                            List <short> values = (List <short>)kerning.GetValue(first);
                            if (values == null)
                            {
                                values = new List <short>();
                                kerning.Put(first, values);
                            }
                            values.Add((short)((offset << 8) | second));
                        }
                    }
                }

                this.chars = new CharDef[maxChar + 1];

                for (IEnumerator <CharDef> iter = charDefs.GetEnumerator(); iter.MoveNext();)
                {
                    CharDef def = (CharDef)iter.Current;
                    chars[def.id] = def;
                }
                ArrayMap.Entry[] entrys = kerning.ToEntrys();
                for (int j = 0; j < entrys.Length; j++)
                {
                    ArrayMap.Entry entry      = entrys[j];
                    short          first      = (short)entry.GetKey();
                    List <short>   valueList  = (List <short>)entry.GetValue();
                    short[]        valueArray = new short[valueList.Count];
                    int            i          = 0;
                    for (IEnumerator <short> valueIter = valueList.GetEnumerator(); valueIter
                         .MoveNext(); i++)
                    {
                        valueArray[i] = (short)valueIter.Current;
                    }
                    chars[first].kerning = valueArray;
                }
            } catch (IOException e) {
                Log.Exception(e);
                throw new Exception("Invalid font file: " + file);
            }
        }