void PostInit() { try { Rules = Ruleset.Load(modData, this, Tileset, RuleDefinitions, WeaponDefinitions, VoiceDefinitions, NotificationDefinitions, MusicDefinitions, SequenceDefinitions); } catch (Exception e) { InvalidCustomRules = true; Rules = Ruleset.LoadDefaultsForTileSet(modData, Tileset); Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message); } Rules.Sequences.Preload(); var tl = new MPos(0, 0).ToCPos(this); var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this); AllCells = new CellRegion(Grid.Type, tl, br); var btl = new PPos(Bounds.Left, Bounds.Top); var bbr = new PPos(Bounds.Right - 1, Bounds.Bottom - 1); SetBounds(btl, bbr); CustomTerrain = new CellLayer <byte>(this); foreach (var uv in AllCells.MapCoords) { CustomTerrain[uv] = byte.MaxValue; } AllEdgeCells = UpdateEdgeCells(); }
public void SetRulesetGenerator(ModData modData, Func <Pair <Ruleset, bool> > generator) { InvalidCustomRules = false; RulesLoaded = false; DefinesUnsafeCustomRules = false; // Note: multiple threads may try to access the value at the same time // We rely on the thread-safety guarantees given by Lazy<T> to prevent race conitions. // If you're thinking about replacing this, then you must be careful to keep this safe. rules = Exts.Lazy(() => { if (generator == null) { return(Ruleset.LoadDefaultsForTileSet(modData, TileSet)); } try { var ret = generator(); DefinesUnsafeCustomRules = ret.Second; return(ret.First); } catch (Exception e) { Log.Write("debug", "Failed to load rules for `{0}` with error :{1}", Title, e.Message); InvalidCustomRules = true; return(Ruleset.LoadDefaultsForTileSet(modData, TileSet)); } finally { RulesLoaded = true; } }); }