static void DoUpdateBot(PlayerBot bot, bool save) { foreach (BotProperties props in SavedBots) { if (bot.name != props.Name || bot.level.name != props.Level) { continue; } props.FromBot(bot); if (save) { Save(); } return; } BotProperties newProps = new BotProperties(); newProps.FromBot(bot); SavedBots.Add(newProps); if (save) { Save(); } }
static void SaveCore(Level lvl) { PlayerBot[] bots = lvl.Bots.Items; string path = Paths.BotsPath(lvl.MapName); if (!File.Exists(path) && bots.Length == 0) { return; } List <BotProperties> props = new List <BotProperties>(bots.Length); for (int i = 0; i < bots.Length; i++) { BotProperties data = new BotProperties(); data.FromBot(bots[i]); props.Add(data); } try { using (StreamWriter w = new StreamWriter(path)) { WriteAll(w, props); } } catch (Exception ex) { Logger.LogError("Error saving bots to " + path, ex); } }
static void SaveCore(Level lvl) { PlayerBot[] bots = lvl.Bots.Items; string path = BotsPath(lvl.MapName); if (!File.Exists(path) && bots.Length == 0) { return; } BotProperties[] props = new BotProperties[bots.Length]; for (int i = 0; i < props.Length; i++) { BotProperties savedProps = new BotProperties(); savedProps.FromBot(bots[i]); props[i] = savedProps; } string json = JsonConvert.SerializeObject(props); try { File.WriteAllText(path, json); } catch (Exception ex) { Logger.Log(LogType.Warning, "Failed to save bots file"); Logger.LogError(ex); } }