Exemple #1
0
            private void changeCustomRibbon(LogbookEntry log)
            {
                string code = "X" + log.Code.Substring(2);

                if (Log.IsLogable(Log.LEVEL.TRACE))
                {
                    Log.Trace("changing custom ribbon for code " + code);
                }

                Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(code);

                if (ribbon == null)
                {
                    Log.Error("invalid custom ribbon code: " + code);
                    return;
                }
                //
                CustomAchievement achievement = ribbon.GetAchievement() as CustomAchievement;

                if (achievement == null)
                {
                    Log.Error("invalid custom ribbon achievement");
                    return;
                }
                achievement.SetName(log.Name);
                achievement.SetDescription(log.Data);
                if (Log.IsLogable(Log.LEVEL.TRACE))
                {
                    Log.Trace("custom ribbonchanged");
                }
            }
Exemple #2
0
            public override void DoDataChange(object[] parameter)
            {
                if (parameter.Count() < 3)
                {
                    Log.Warning("invalid parameter count for custom ribbon change");
                    return;
                }

                string s0 = parameter[0] as string;
                string s1 = parameter[1] as string;
                string s2 = parameter[2] as string;

                if (s0 == null || s1 == null || s2 == null)
                {
                    Log.Warning("invalid parameter type for custom ribbon change");
                    return;
                }

                string code = "X" + s0.Substring(2);
                string name = s1;
                string text = s2;

                if (Log.IsLogable(Log.LEVEL.TRACE))
                {
                    Log.Trace("changing custom ribbon for code " + code);
                }

                Ribbon ribbon = RibbonPool.Instance().GetRibbonForCode(code);

                if (ribbon == null)
                {
                    Log.Error("invalid custom ribbon code: " + code);
                    return;
                }
                //
                CustomAchievement achievement = ribbon.GetAchievement() as CustomAchievement;

                if (achievement == null)
                {
                    Log.Error("invalid custom ribbon achievement");
                    return;
                }
                achievement.SetName(name);
                achievement.SetDescription(text);
                if (Log.IsLogable(Log.LEVEL.TRACE))
                {
                    Log.Trace("custom ribbon changed");
                }
            }
            private void AwardSelectedCustomRibbon()
            {
                if (selected == null)
                {
                    Log.Warning("no custom ribbon selected");
                    return;
                }

                CustomAchievement achievement = selected.GetAchievement() as CustomAchievement;

                if (achievement == null)
                {
                    Log.Warning("invalid custom ribbon");
                    return;
                }

                // changed name or text?
                if (!achievement.GetDescription().Equals(customRibbonText) || !achievement.GetName().Equals(customRibbonName))
                {
                    Log.Detail("name or text change of ribbon " + selected.GetCode());
                    // change name and text
                    achievement.SetName(customRibbonName);
                    achievement.SetDescription(customRibbonText);
                    // record changed ribbon
                    HallOfFame.Instance().RecordCustomRibbon(selected);
                }

                // assign ribbon to kerbal
                Log.Trace("assigning custom ribbon " + selected + " to kerbal " + entry.GetKerbal().name + " at game time " +
                          Planetarium.GetUniversalTime());
                HallOfFame.Instance().BeginArwardOfRibbons();
                HallOfFame.Instance().Record(entry.GetKerbal(), selected);
                HallOfFame.Instance().EndArwardOfRibbons();
                //
                // mark game as updated, if not in flight
                if (HighLogic.LoadedScene != GameScenes.FLIGHT)
                {
                    Log.Trace("mark game as updated");
                    HighLogic.CurrentGame.Updated();
                }
            }
Exemple #4
0
 private void ReadLine(string line)
 {
     // ignore comments
     if (!line.StartsWith("#") && line.Length > 0)
     {
         string[] fields = line.Split(':');
         if (fields.Length > 0)
         {
             string what = fields[0];
             if (what.Equals("NAME") && fields.Length == 2)
             {
                 this.name = fields[1];
             }
             else if (what.Equals("FOLDER") && fields.Length == 2)
             {
                 this.ribbonFolder = baseFolder + "/" + fields[1];
                 Log.Detail("changing ribbon folder of ribbon pack '" + name + "' to '" + this.ribbonFolder + "'");
             }
             else if (what.Equals("BASE") && fields.Length == 2)
             {
                 try
                 {
                     this.baseId = int.Parse(fields[1]);
                     Log.Detail("changing base id of ribbon pack '" + name + "' to " + this.baseId);
                 }
                 catch
                 {
                     Log.Error("failed to parse custom ribbon base id");
                 }
             }
             else if (fields.Length == 4 || fields.Length == 5)
             {
                 int id;
                 try
                 {
                     id = baseId + int.Parse(fields[0]);
                 }
                 catch
                 {
                     Log.Error("failed to parse custom ribbon id");
                     return;
                 }
                 string fileOfRibbon     = ribbonFolder + "/" + fields[1];
                 string nameOfRibbon     = fields[2];
                 string descOfRibbon     = fields[3];
                 int    prestigeOfRibbon = id;
                 if (fields.Length == 5)
                 {
                     try
                     {
                         prestigeOfRibbon = int.Parse(fields[4]);
                     }
                     catch
                     {
                         Log.Error("failed to parse custom ribbon id");
                     }
                 }
                 try
                 {
                     Log.Detail("adding custom ribbon '" + nameOfRibbon + "' (id " + id + ") to ribbon pack '" + name + "'");
                     Log.Trace("path of custom ribbon file is '" + fileOfRibbon + "'");
                     CustomAchievement achievement = new CustomAchievement(id, prestigeOfRibbon);
                     achievement.SetName(nameOfRibbon);
                     achievement.SetDescription(descOfRibbon);
                     Ribbon ribbon = new Ribbon(fileOfRibbon, achievement);
                     ribbons.Add(ribbon);
                 }
                 catch
                 {
                     Log.Warning("failed to add custom ribbon '" + nameOfRibbon + "' to ribbon pack '" + name + "'");
                 }
             }
             else
             {
                 Log.Warning("invalid ribbon pack file for " + name + " custom ribbon pack. failed to parse line '" + line + "'");
             }
         }
     }
 }