yellowstonegames / SquidLib

Useful tools for roguelike, role-playing, strategy, and other grid-based games in Java. Feedback is welcome!
Other
455 stars 46 forks source link

Make dungeon generators all implement a single interface. #152

Closed Duke02 closed 7 years ago

Duke02 commented 7 years ago

We could have an interface that all dungeon generators implement from. The interface could be something like this -

public interface IDungeonGenerator {

    public char[][] generate( /* Necessary parameters */ );

}

and potentially other functions if the need arises. This would entail some renaming of most dungeon generators.

This interface could then be used for flexible dungeon generation, such as -

public class Dungeon {

    char[][] dungeon;

    public Dungeon(IDungeonGenerator dungeonGenerator) {

        this.dungeon = dungeonGenerator.generate();

    }

}
tommyettinger commented 7 years ago

I like this idea, but there are some things to figure out. The generate() method definitely works over all of them, no question, but for at least SectionDungeonGenerator (probably also ThinDungeonGenerator), the addDoors(), addWater(), and similar methods take an extra parameter for what dungeon areas (room, corridor, or cave) should be affected. There could be a standard IDungeonGenerator method that always means "apply to all possible cells", which is the only option in DungeonGenerator, and can also be done in SectionDungeonGenerator by using the existing methods and passing a specific environment type. This would be harder to connect to addLake() and addMaze(), which aren't in DungeonGenerator. If the only methods are related to generating a dungeon and getting the last generated dungeon, then this would need almost no code to implement, plus it lets the existing implementations add extra features that make sense in their own context but not others (ThinDungeonGenerator especially needs this to handle its unusual map requirements). So, I'll make a simple interface with just:

char[][] generate();
char[][] getDungeon();

Since all the dungeon generators can for sure do those two things, anything else can be specially assigned to a specific instance, but the general usage as a generator works for all of them.

smelc commented 7 years ago

@tommyettinger> the "add" methods in IDungeonGenerator could return a boolean indicating if the request could be honored. Dungeon generators that do not know lakes and mazes would return false for these methods.

tommyettinger commented 7 years ago

I think I will close this for now, since c054fae74f3ab239aab0d5df9ec34890e6c0e530 covers the basic "can it generate a 2D char array" function for a lot of classes, but I am happy to reopen it if there's some specific functionality that should be wrapped in this or a similar interface, maybe for a smaller subset of classes that also share methods.