Alright, formulated this way I'm sure it sounds obscure, but I'll do my best to describe my problem.
First, let me explain what's wrong with my real source code.
I'm making a platformer, and here are the current components of my game: a Level, which is holding its own grid of tiles and also the tile sheets and a Tile, which just keeps the name of its tile sheet and index within the tile sheet. All these are within a separate XNA game project, named GameLib.
Here is how my levels are formatted in a text file:
x x . . . . .
. . . b g r .
. . . . . . .
X X X X X X X
Where .
represents an empty tile, b
represents a blue platform, X
represents a block with a random color, etc.
Instead of doing all the work of loading a level within the Level class, I decided to take advantage of the content pipeline extension and create a LevelContentPipelineExtension.
As soon as I started, I quickly realized that I didn't want to hard-code 20+ lines of the kind:
if (symbol == 'b')
return new Tile(/*...*/);
So, in the hope of at least centralizing all the content creation into one class, I made a static class, called LevelContentCreation, which holds the information about which symbol creates what and all this kind of stuff. It also holds a list of all the asset paths of the tile sheets, to load them later on. This class is within my GameLib game library project.
The problem is, I'm using this LevelContentCreation static class in both my Level class (to load the actual tile sheets) and my content pipeline extension (to know which symbol represents what tile)...
And here's how my LevelContentCreation class looks like:
public static class LevelContentCreation
{
private static Dictionary<char, TileCreationInfo> AvailableTiles =
CreateAvailableTiles();
private static List<string> AvailableTileSheets { get; set; }
/* ... rest of the class */
}
Now, since the LevelContentCreation class is part of the game library, the content pipeline extension tries to use it but the call to CreateAvailableTiles() never happens and I'm unable to load a Level object from the content pipeline.
I know this is because the content pipeline executes before the actual compilation or something like that, but how can I fix the problem?
I can't really move the LevelContentCreation class to the pipeline extension, because then the Level class wouldn't be able to use it... I'm pretty lost and I don't know what to do... I know these are pretty bad design decisions, and I'd like it if somebody could point me in the right direction.
Thank you for your precious time.
If anything is not clear enough or if I should provide more information/code, please leave a comment below.