Skip to content

Commit

Permalink
* Atmos now works with WinDoors
Browse files Browse the repository at this point in the history
* Added .DotSettings files to gitignore
  • Loading branch information
krille90 committed Feb 16, 2019
1 parent 987cf3a commit 3a57e2a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ UnityProject/ProjectSettings/ProjectVersion.txt
UnityProject/.vscode/settings.json
UnityProject/Assets/StreamingAssets/config.meta
UnityProject/Assets/UI/Fonts/Font_Awesome_4.7.0.meta
*.DotSettings
180 changes: 86 additions & 94 deletions UnityProject/Assets/Scripts/Tilemaps/Behaviours/Layers/ObjectLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,129 +3,121 @@
using UnityEngine;


/// <summary>
/// ObjectLayer holds all the objects on all the tiles in the game world - specifically the RegisterTile components of those objects.
/// It provides functionality for checking what should occur on given tiles, such as if a tile at a specific location should be passable.
/// </summary>
[ExecuteInEditMode]
public class ObjectLayer : Layer
/// <summary>
/// ObjectLayer holds all the objects on all the tiles in the game world - specifically the RegisterTile components of those objects.
/// It provides functionality for checking what should occur on given tiles, such as if a tile at a specific location should be passable.
/// </summary>
[ExecuteInEditMode]
public class ObjectLayer : Layer
{
private TileList _objects;

public TileList Objects => _objects ?? (_objects = new TileList());

public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix)
{
private TileList _objects;
ObjectTile objectTile = tile as ObjectTile;

public TileList Objects => _objects ?? (_objects = new TileList());

public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix)
if (objectTile)
{
ObjectTile objectTile = tile as ObjectTile;

if (objectTile)
if (!objectTile.IsItem)
{
if (!objectTile.IsItem)
{
tilemap.SetTile(position, null);
}
objectTile.SpawnObject(position, tilemap, transformMatrix);
tilemap.SetTile(position, null);
}
else
{
base.SetTile(position, tile, transformMatrix);
}
}

public override bool HasTile(Vector3Int position)
objectTile.SpawnObject(position, tilemap, transformMatrix);
}
else
{
return Objects.Get(position).Count > 0 || base.HasTile(position);
base.SetTile(position, tile, transformMatrix);
}
}

public override void RemoveTile(Vector3Int position, bool removeAll=false)
{
List<RegisterTile> objs = Objects.Get(position);
for ( var i = 0; i < objs.Count; i++ ) {
RegisterTile obj = objs[i];
DestroyImmediate( obj.gameObject );
}
public override bool HasTile(Vector3Int position)
{
return Objects.Get(position).Count > 0 || base.HasTile(position);
}

base.RemoveTile(position, removeAll);
public override void RemoveTile(Vector3Int position, bool removeAll = false)
{
List<RegisterTile> objs = Objects.Get(position);
for (var i = 0; i < objs.Count; i++)
{
RegisterTile obj = objs[i];
DestroyImmediate(obj.gameObject);
}

public override bool IsPassableAt( Vector3Int origin, Vector3Int to, bool inclPlayers = true, GameObject context = null )
base.RemoveTile(position, removeAll);
}

public override bool IsPassableAt(Vector3Int origin, Vector3Int to, bool inclPlayers = true, GameObject context = null)
{
//Targeting windoors here
List<RegisterTile> objectsOrigin = Objects.Get(origin);
for (var i = 0; i < objectsOrigin.Count; i++)
{
//Targeting windoors here
List<RegisterTile> objectsOrigin = Objects.Get(origin);
for ( var i = 0; i < objectsOrigin.Count; i++ ) {
if ( !objectsOrigin[i].IsPassableTo( to ) && ( !context || objectsOrigin[i].gameObject != context ) ) {
//Can't get outside the tile because windoor doesn't allow us
return false;
}
if (!objectsOrigin[i].IsPassableTo(to) && (!context || objectsOrigin[i].gameObject != context))
{
//Can't get outside the tile because windoor doesn't allow us
return false;
}
}

List<RegisterTile> objectsTo = Objects.Get(to);
bool toPass;
if ( inclPlayers ) {
toPass = true;
for ( var i = 0; i < objectsTo.Count; i++ ) {
RegisterTile o = objectsTo[i];
if ( !o.IsPassable( origin ) && ( !context || o.gameObject != context ) ) {
toPass = false;
break;
}
}
} else {
toPass = true;
for ( var i = 0; i < objectsTo.Count; i++ ) {
RegisterTile o = objectsTo[i];
if ( o.ObjectType != ObjectType.Player && !o.IsPassable( origin ) && ( !context || o.gameObject != context ) ) {
toPass = false;
break;
}
}
List<RegisterTile> objectsTo = Objects.Get(to);

for (var i = 0; i < objectsTo.Count; i++)
{
RegisterTile o = objectsTo[i];
if ((inclPlayers || o.ObjectType != ObjectType.Player) && !o.IsPassable(origin) && (!context || o.gameObject != context))
{
return false;
}
}

bool rods = base.IsPassableAt(origin, to, inclPlayers);
return base.IsPassableAt(origin, to, inclPlayers);
}

// Logger.Log( $"IPA = {toPass} && {rods} @ {MatrixManager.Instance.LocalToWorldInt( origin, MatrixManager.Get(0).Matrix )} -> {MatrixManager.Instance.LocalToWorldInt( to, MatrixManager.Get(0).Matrix )} " +
// $" (in local: {origin} -> {to})", Category.Matrix );
return toPass && rods;
}
public override bool IsAtmosPassableAt(Vector3Int origin, Vector3Int to)
{
List<RegisterTile> objectsTo = Objects.Get(to);

public override bool IsAtmosPassableAt(Vector3Int origin, Vector3Int to)
for (int i = 0; i < objectsTo.Count; i++)
{
List<RegisterTile> objectsTo = Objects.Get(to);

for (int i = 0; i < objectsTo.Count; i++)
if (!objectsTo[i].IsAtmosPassable(origin))
{
if (!objectsTo[i].IsAtmosPassable())
{
return false;
}
return false;
}
}

List<RegisterTile> objectsOrigin = Objects.Get(origin);
List<RegisterTile> objectsOrigin = Objects.Get(origin);

for (int i = 0; i < objectsOrigin.Count; i++)
for (int i = 0; i < objectsOrigin.Count; i++)
{
if (!objectsOrigin[i].IsAtmosPassable(to))
{
if (!objectsOrigin[i].IsAtmosPassable())
{
return false;
}
return false;
}

return base.IsAtmosPassableAt(origin, to);
}

public override bool IsSpaceAt(Vector3Int position)
{
return IsAtmosPassableAt(position, position) && base.IsSpaceAt(position);
}
return base.IsAtmosPassableAt(origin, to);
}

public override void ClearAllTiles() {
for ( var i = 0; i < Objects.AllObjects.Count; i++ ) {
RegisterTile obj = Objects.AllObjects[i];
if ( obj != null ) {
DestroyImmediate( obj.gameObject );
}
}
public override bool IsSpaceAt(Vector3Int position)
{
return IsAtmosPassableAt(position, position) && base.IsSpaceAt(position);
}

base.ClearAllTiles();
public override void ClearAllTiles()
{
for (var i = 0; i < Objects.AllObjects.Count; i++)
{
RegisterTile obj = Objects.AllObjects[i];
if (obj != null)
{
DestroyImmediate(obj.gameObject);
}
}

base.ClearAllTiles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ public override bool IsPassable()
return !isClosed;
}

public override bool IsAtmosPassable()
public override bool IsAtmosPassable(Vector3Int from)
{
return !isClosed || OneDirectionRestricted;
if (isClosed && OneDirectionRestricted)
{
// OneDirectionRestricted is hardcoded to only be from the negative y position
Vector3Int v = Vector3Int.RoundToInt(transform.localRotation * Vector3.down);

// Returns false if player is bumping door from the restricted direction
return !(from - Position).y.Equals(v.y);
}

return !isClosed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public override bool IsPassable()
return Passable || Position == TransformState.HiddenPos;
}

public override bool IsAtmosPassable()
public override bool IsAtmosPassable(Vector3Int from)
{
return AtmosPassable || Position == TransformState.HiddenPos;
}
}

#region UI Mouse Actions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public virtual bool IsPassableTo(Vector3Int to)
return true;
}

public virtual bool IsAtmosPassable()
public virtual bool IsAtmosPassable(Vector3Int from)
{
return true;
}
Expand Down

0 comments on commit 3a57e2a

Please sign in to comment.