Add some state info and save method

This commit is contained in:
NGnius (Graham) 2020-06-26 19:37:58 -04:00
parent 189c3ca2a5
commit b6a5074fd2
3 changed files with 61 additions and 0 deletions

View file

@ -65,6 +65,15 @@ namespace GamecraftModdingAPI.App
}
}
/// <summary>
/// Whether Gamecraft is in the Main Menu
/// </summary>
/// <value><c>true</c> if in menu; <c>false</c> when loading or in a game.</value>
public bool InMenu
{
get => appEngine.IsInMenu;
}
internal static void Init()
{
MenuEngineManager.AddMenuEngine(appEngine);

View file

@ -7,6 +7,8 @@ using RobocraftX.GUI.MyGamesScreen;
using RobocraftX.StateSync;
using Svelto.ECS;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Tasks;
using GamecraftModdingAPI.Utility;
@ -414,6 +416,28 @@ namespace GamecraftModdingAPI.App
return debugIds.Remove(id);
}
/// <summary>
/// Gets the blocks in the game.
/// This returns null when in a loading state, and throws AppStateException when in menu.
/// </summary>
/// <returns>The blocks in game.</returns>
/// <param name="filter">The block to search for. BlockIDs.Invalid will return all blocks.</param>
public Block[] GetBlocksInGame(BlockIDs filter = BlockIDs.Invalid)
{
if (!VerifyMode()) return null;
if (menuMode)
{
throw new AppStateException("Game object references a menu item but GetBlocksInGame only works on the currently-loaded game");
}
EGID[] blockEGIDs = gameEngine.GetAllBlocksInGame(filter);
Block[] blocks = new Block[blockEGIDs.Length];
for (int b = 0; b < blockEGIDs.Length; b++)
{
blocks[b] = new Block(blockEGIDs[b]);
}
return blocks;
}
~Game()
{
foreach (string id in debugIds)

View file

@ -10,6 +10,7 @@ using Svelto.ECS;
using Svelto.Tasks;
using Svelto.Tasks.Lean;
using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Utility;
@ -93,5 +94,32 @@ namespace GamecraftModdingAPI.App
{
TimeRunningModeUtil.ToggleTimeRunningState(entitiesDB);
}
public EGID[] GetAllBlocksInGame(BlockIDs filter = BlockIDs.Invalid)
{
EntityCollection<DBEntityStruct> blocks = entitiesDB.QueryEntities<DBEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
if (filter == BlockIDs.Invalid)
{
EGID[] blockEGIDs = new EGID[blocks.count];
for (uint b = 0; b < blocks.count; b++)
{
blockEGIDs[b] = blocks[b].ID;
}
return blockEGIDs;
}
else
{
uint dbidFilter = (uint)filter;
List<EGID> blockEGIDs = new List<EGID>();
for (uint b = 0; b < blocks.count; b++)
{
if (blocks[b].DBID == dbidFilter)
{
blockEGIDs.Add(blocks[b].ID);
}
}
return blockEGIDs.ToArray();
}
}
}
}