public CustomTerrainTemplateInfo(ITerrainInfo terrainInfo, MiniYaml my) : base(terrainInfo, my) { AutoConnect = my.Nodes.Where(n => n.Key.StartsWith("AutoConnect")) .Select(y => new AutoConnectInfo(y.Value)) .ToArray(); }
private static void OnTerrainPainted(ITerrainInfo tile, ToolAction action) { for (int i = 0; i < s_PaintedTerrain.Count; ++i) { if (tile.terrain == s_PaintedTerrain[i].terrain) { var pt = s_PaintedTerrain[i]; // round-about assignment here because of struct copy semantics pt.action |= action; s_PaintedTerrain[i] = pt; return; } } s_PaintedTerrain.Add(new PaintedTerrain { terrain = tile.terrain, action = action }); }
public UndergroundEditorResourceLayer(Actor self) { if (self.World.Type != WorldType.Editor) { return; } Map = self.World.Map; TerrainInfo = self.World.Map.Rules.TerrainInfo; Tiles = new CellLayer <ResourceLayerContents>(Map); Resources = self.TraitsImplementing <ResourceType>() .ToDictionary(r => r.Info.ResourceType, r => r); Map.Resources.CellEntryChanged += UpdateCell; }
private SplatmapUserData GetTerrainLayerUserData(ITerrainInfo context, TerrainLayer terrainLayer = null, bool addLayerIfDoesntExist = false) { // look up existing user data, if any SplatmapUserData userData = (context.userData as SplatmapUserData); if (userData != null) { // check if it is appropriate, return if so if ((terrainLayer == null) || (terrainLayer == userData.terrainLayer)) { return(userData); } else { userData = null; } } // otherwise let's build it if (userData == null) { int tileLayerIndex = -1; if (terrainLayer != null) { // look for the layer on the terrain tileLayerIndex = TerrainPaintUtility.FindTerrainLayerIndex(context.terrain, terrainLayer); if ((tileLayerIndex == -1) && (addLayerIfDoesntExist)) { onTerrainTileBeforePaint?.Invoke(context, ToolAction.AddTerrainLayer, "Adding Terrain Layer"); tileLayerIndex = TerrainPaintUtility.AddTerrainLayer(context.terrain, terrainLayer); } } // if we found the layer, build user data if (tileLayerIndex != -1) { userData = new SplatmapUserData(); userData.terrainLayer = terrainLayer; userData.terrainLayerIndex = tileLayerIndex; userData.mapIndex = tileLayerIndex >> 2; userData.channelIndex = tileLayerIndex & 0x3; } context.userData = userData; } return(userData); }
public TerrainTemplateInfo(ITerrainInfo terrainInfo, MiniYaml my) { FieldLoader.Load(this, my); var nodes = my.ToDictionary()["Tiles"].Nodes; if (!PickAny) { tileInfo = new TerrainTileInfo[Size.X * Size.Y]; foreach (var node in nodes) { if (!int.TryParse(node.Key, out var key)) { throw new YamlException($"Tileset `{terrainInfo.Id}` template `{Id}` defines a frame `{node.Key}` that is not a valid integer."); } if (key < 0 || key >= tileInfo.Length) { throw new YamlException($"Tileset `{terrainInfo.Id}` template `{Id}` references frame {key}, but only [0..{tileInfo.Length - 1}] are valid for a {Size.X}x{Size.Y} Size template."); } tileInfo[key] = LoadTileInfo(terrainInfo, node.Value); } } else { tileInfo = new TerrainTileInfo[nodes.Count]; var i = 0; foreach (var node in nodes) { if (!int.TryParse(node.Key, out var key)) { throw new YamlException($"Tileset `{terrainInfo.Id}` template `{Id}` defines a frame `{node.Key}` that is not a valid integer."); } if (key != i++) { throw new YamlException($"Tileset `{terrainInfo.Id}` template `{Id}` is missing a definition for frame {i - 1}."); } tileInfo[key] = LoadTileInfo(terrainInfo, node.Value); } } }
protected virtual TerrainTileInfo LoadTileInfo(ITerrainInfo terrainInfo, MiniYaml my) { var tile = new TerrainTileInfo(); FieldLoader.Load(tile, my); // Terrain type must be converted from a string to an index tile.GetType().GetField(nameof(tile.TerrainType)).SetValue(tile, terrainInfo.GetTerrainIndex(my.Value)); // Fall back to the terrain-type color if necessary var overrideColor = terrainInfo.TerrainTypes[tile.TerrainType].Color; if (tile.MinColor == default) { tile.GetType().GetField(nameof(tile.MinColor)).SetValue(tile, overrideColor); } if (tile.MaxColor == default) { tile.GetType().GetField(nameof(tile.MaxColor)).SetValue(tile, overrideColor); } return(tile); }
public CustomTerrainTemplateInfo(ITerrainInfo terrainInfo, MiniYaml my) : base(terrainInfo, my) { }
public Ruleset( IReadOnlyDictionary <string, ActorInfo> actors, IReadOnlyDictionary <string, WeaponInfo> weapons, IReadOnlyDictionary <string, SoundInfo> voices, IReadOnlyDictionary <string, SoundInfo> notifications, IReadOnlyDictionary <string, MusicInfo> music, ITerrainInfo terrainInfo, SequenceProvider sequences, IReadOnlyDictionary <string, MiniYamlNode> modelSequences) { Actors = new ActorInfoDictionary(actors); Weapons = weapons; Voices = voices; Notifications = notifications; Music = music; TerrainInfo = terrainInfo; Sequences = sequences; ModelSequences = modelSequences; foreach (var a in Actors.Values) { foreach (var t in a.TraitInfos <IRulesetLoaded>()) { try { t.RulesetLoaded(this, a); } catch (YamlException e) { throw new YamlException($"Actor type {a.Name}: {e.Message}"); } } } foreach (var weapon in Weapons) { if (weapon.Value.Projectile is IRulesetLoaded <WeaponInfo> projectileLoaded) { try { projectileLoaded.RulesetLoaded(this, weapon.Value); } catch (YamlException e) { throw new YamlException($"Projectile type {weapon.Key}: {e.Message}"); } } foreach (var warhead in weapon.Value.Warheads) { if (warhead is IRulesetLoaded <WeaponInfo> cacher) { try { cacher.RulesetLoaded(this, weapon.Value); } catch (YamlException e) { throw new YamlException($"Weapon type {weapon.Key}: {e.Message}"); } } } } }
public DefaultTerrainTemplateInfo(ITerrainInfo terrainInfo, MiniYaml my) : base(terrainInfo, my) { }
public Ruleset( IReadOnlyDictionary <string, ActorInfo> actors, IReadOnlyDictionary <string, WeaponInfo> weapons, IReadOnlyDictionary <string, SoundInfo> voices, IReadOnlyDictionary <string, SoundInfo> notifications, IReadOnlyDictionary <string, MusicInfo> music, ITerrainInfo terrainInfo, SequenceProvider sequences, IReadOnlyDictionary <string, MiniYamlNode> modelSequences) { Actors = actors; Weapons = weapons; Voices = voices; Notifications = notifications; Music = music; TerrainInfo = terrainInfo; Sequences = sequences; ModelSequences = modelSequences; foreach (var a in Actors.Values) { foreach (var t in a.TraitInfos <IRulesetLoaded>()) { try { t.RulesetLoaded(this, a); } catch (YamlException e) { throw new YamlException("Actor type {0}: {1}".F(a.Name, e.Message)); } } } foreach (var weapon in Weapons) { var projectileLoaded = weapon.Value.Projectile as IRulesetLoaded <WeaponInfo>; if (projectileLoaded != null) { try { projectileLoaded.RulesetLoaded(this, weapon.Value); } catch (YamlException e) { throw new YamlException("Projectile type {0}: {1}".F(weapon.Key, e.Message)); } } foreach (var warhead in weapon.Value.Warheads) { var cacher = warhead as IRulesetLoaded <WeaponInfo>; if (cacher != null) { try { cacher.RulesetLoaded(this, weapon.Value); } catch (YamlException e) { throw new YamlException("Weapon type {0}: {1}".F(weapon.Key, e.Message)); } } } } }