Giter Site home page Giter Site logo

Comments (1)

OndrejNepozitek avatar OndrejNepozitek commented on June 15, 2024

Hey! Thanks for the suggestion.

If I understand your suggestion correctly, these sub-shapes would not change the outline of the rooms, so they would not change the behaviour of the layouting algorithm. If this is the case, it's probably not a good idea to add these sub-shapes to the algorithm itself because it would slow it down.

It would be probably better to implement this as a postprocessing step on the output of the algorithm. I added (release 1.0.6, master branch) a simple extension method to the IRoom interface that should help you do this. It could be done as follows:

  • Create classic room descriptions for room types
  • Define your slots for each room type e.g. as lists of IntVector2and create a mapping from room types to these lists of slots
  • Run the algorithm, it produces a position and a room shape for each node in the input graph
  • Take the generated layout, go through each room
    • find associated slots
    • the room may have been transformed (e.g. rotated and moved) - so you have to transform all the slots - there is a TransformPointToNewPosition extension method on the IRoom interface and you should use it on all your slots
    • now you have the slot positions of a given room in the final layout

I also implemented an integration test that should demonstrate how it could be done (here):

// Create a rectangular room shape
// Move it away from (0, 0) so that we can properly test the functionality
var rectangleShape = GridPolygon.GetRectangle(10, 4) + new IntVector2(10, 10);

// Create points to be transformed
// These could be for example traps, spawn points, etc.
// We use points of the rectangle here because it is easy to check that the transformation is correct.
var pointsToTransform = rectangleShape.GetPoints();

var mapDescription = new MapDescription<int>();

// Create simple graph with 2 vertices and 1 edge
mapDescription.AddRoom(0);
mapDescription.AddRoom(1);
mapDescription.AddPassage(0, 1);

// Add the rectangle shape
mapDescription.AddRoomShapes(new RoomDescription(rectangleShape, new OverlapMode(1, 0)));

var layoutGenerator = LayoutGeneratorFactory.GetDefaultChainBasedGenerator<int>();
var layout = layoutGenerator.GetLayouts(mapDescription, 1)[0];

foreach (var room in layout.Rooms)
{
    // The points were chosen to be the points of the polygon, so after transforming them, they should
    // be equal to the room.Shape + room.Position points
    var transformedPoints = pointsToTransform.Select(x => room.TransformPointToNewPosition(x));
    var expectedPoints = (room.Shape + room.Position).GetPoints();

    Assert.That(transformedPoints, Is.EquivalentTo(expectedPoints));
}

Is this a solution to your problem/suggestion?

from edgar-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.