Skip to content

Commit

Permalink
Add command for creating simple planet maps (space-wizards#12698)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Nov 23, 2022
1 parent 23be8a1 commit 375490b
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 0 deletions.
95 changes: 95 additions & 0 deletions Content.Server/Maps/PlanetCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System.Linq;
using Content.Server.Administration;
using Content.Server.Atmos;
using Content.Server.Atmos.Components;
using Content.Server.Gravity.EntitySystems;
using Content.Shared.Administration;
using Content.Shared.Atmos;
using Content.Shared.Gravity;
using Content.Shared.Movement.Components;
using Content.Shared.Parallax;
using Robust.Shared.Audio;
using Robust.Shared.Console;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;

namespace Content.Server.Maps;

/// <summary>
/// Converts the supplied map into a "planet" with defaults.
/// </summary>
[AdminCommand(AdminFlags.Mapping)]
public sealed class PlanetCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;

public string Command => $"planet";
public string Description => Loc.GetString("cmd-planet-desc");
public string Help => Loc.GetString("cmd-planet-help", ("command", Command));
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteError(Loc.GetString($"cmd-planet-args"));
return;
}

if (!int.TryParse(args[0], out var mapInt))
{
shell.WriteError(Loc.GetString($"cmd-planet-map", ("map", mapInt)));
return;
}

var mapId = new MapId(mapInt);

if (!_mapManager.MapExists(mapId))
{
shell.WriteError(Loc.GetString($"cmd-planet-map", ("map", mapId)));
return;
}

var mapUid = _mapManager.GetMapEntityId(mapId);
MetaDataComponent? metadata = null;

var parallax = _entManager.EnsureComponent<ParallaxComponent>(mapUid);
parallax.Parallax = "Grass";
_entManager.Dirty(parallax, metadata);
var gravity = _entManager.EnsureComponent<GravityComponent>(mapUid);
gravity.Enabled = true;
_entManager.Dirty(gravity);
_entManager.EnsureComponent<MapLightComponent>(mapUid);
var atmos = _entManager.EnsureComponent<MapAtmosphereComponent>(mapUid);

atmos.Space = false;
var moles = new float[Atmospherics.TotalNumberOfGases];
moles[(int) Gas.Oxygen] = 21.824779f;
moles[(int) Gas.Nitrogen] = 82.10312f;

atmos.Mixture = new GasMixture(2500)
{
Temperature = 293.15f,
Moles = moles,
};

var footstep = _entManager.EnsureComponent<FootstepModifierComponent>(mapUid);
footstep.Sound = new SoundCollectionSpecifier("FootstepGrass");
_entManager.Dirty(footstep);

_entManager.EnsureComponent<MapGridComponent>(mapUid);
shell.WriteLine(Loc.GetString("cmd-planet-success", ("mapId", mapId)));
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length != 1)
{
return CompletionResult.Empty;
}

var options = _entManager.EntityQuery<MapComponent>(true)
.Select(o => new CompletionOption(o.WorldMap.ToString(), "MapId"));

return CompletionResult.FromOptions(options);
}
}
5 changes: 5 additions & 0 deletions Resources/Locale/en-US/maps/planet.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmd-planet-desc = Converts the supplied map into a planet with sensible defaults.
cmd-planet-help = {$command} <mapid>.
cmd-planet-args = Require 1 arg only.
cmd-planet-map = Unable to parse {$map} as an existing map.
cmd-planet-success = Set map {$mapId} to Planet. NOTE! You will need to load the map (either onto a new map or by restarting the game) for atmospherics to work.
10 changes: 10 additions & 0 deletions Resources/Prototypes/Parallaxes/planet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
scale: "2, 2"
scrolling: "0.1, -0.05"

- type: parallax
id: Grass
layers:
- texture:
!type:ImageParallaxTextureSource
path: "/Textures/Tiles/Planet/grass.rsi/grass0.png"
slowness: 0
scale: "1, 1"
shader: ""

- type: parallax
id: Snow
layers:
Expand Down
Binary file added Resources/Textures/Tiles/Planet/grass.rsi/grass0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Textures/Tiles/Planet/grass.rsi/grass1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Textures/Tiles/Planet/grass.rsi/grass2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/Textures/Tiles/Planet/grass.rsi/grass3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions Resources/Textures/Tiles/Planet/grass.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "https://github.com/discordia-space/CEV-Eris/commit/026ee3250ac1de938b503e3eb46ad73dd9c3ca82",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "grass0"
},
{
"name": "grass1"
},
{
"name": "grass2"
},
{
"name": "grass3"
},
{
"name": "grass_edges",
"directions": 8
},
{
"name": "grass_edges_old",
"directions": 8
},
{
"name": "grass_corners",
"directions": 8
},
{
"name": "grass_edge_corner",
"directions": 8
}
]
}

0 comments on commit 375490b

Please sign in to comment.