2020-06-18 01:04:08 +00:00
|
|
|
|
using System;
|
|
|
|
|
using HarmonyLib;
|
|
|
|
|
|
|
|
|
|
using RobocraftX;
|
|
|
|
|
using RobocraftX.Common;
|
|
|
|
|
using RobocraftX.GUI;
|
|
|
|
|
using RobocraftX.GUI.MyGamesScreen;
|
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
using Svelto.ECS.Experimental;
|
|
|
|
|
|
|
|
|
|
using GamecraftModdingAPI.Engines;
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
2020-08-07 17:55:00 +00:00
|
|
|
|
using Svelto.DataStructures;
|
2020-06-18 01:04:08 +00:00
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.App
|
|
|
|
|
{
|
|
|
|
|
public class GameMenuEngine : IFactoryEngine
|
|
|
|
|
{
|
|
|
|
|
public IEntityFactory Factory { set; private get; }
|
|
|
|
|
|
|
|
|
|
public string Name => "GamecraftModdingAPIGameInfoGameEngine";
|
|
|
|
|
|
|
|
|
|
public bool isRemovable => false;
|
|
|
|
|
|
|
|
|
|
public EntitiesDB entitiesDB { set; private get; }
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
IsInMenu = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Ready()
|
|
|
|
|
{
|
|
|
|
|
IsInMenu = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// game functionality
|
|
|
|
|
|
|
|
|
|
public bool IsInMenu
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
} = false;
|
|
|
|
|
|
|
|
|
|
public bool CreateMyGame(EGID id, string path = "", uint thumbnailId = 0, string gameName = "", string creatorName = "", string description = "", long createdDate = 0L)
|
|
|
|
|
{
|
2021-04-10 00:02:47 +00:00
|
|
|
|
EntityInitializer eci = Factory.BuildEntity<MyGameDataEntityDescriptor_DamnItFJWhyDidYouMakeThisInternal>(id);
|
2020-06-18 01:04:08 +00:00
|
|
|
|
eci.Init(new MyGameDataEntityStruct
|
|
|
|
|
{
|
|
|
|
|
SavedGamePath = new ECSString(path),
|
|
|
|
|
ThumbnailId = thumbnailId,
|
|
|
|
|
GameName = new ECSString(gameName),
|
|
|
|
|
CreatorName = new ECSString(creatorName),
|
|
|
|
|
GameDescription = new ECSString(description),
|
|
|
|
|
CreatedDate = createdDate,
|
|
|
|
|
});
|
|
|
|
|
// entitiesDB.PublishEntityChange<MyGameDataEntityStruct>(id); // this will always fail
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint HighestID()
|
|
|
|
|
{
|
|
|
|
|
EntityCollection<MyGameDataEntityStruct> games = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames);
|
2020-11-09 21:18:25 +00:00
|
|
|
|
var gamesB = games.ToBuffer().buffer;
|
2020-06-18 01:04:08 +00:00
|
|
|
|
uint max = 0;
|
|
|
|
|
for (int i = 0; i < games.count; i++)
|
|
|
|
|
{
|
2020-11-09 21:18:25 +00:00
|
|
|
|
if (gamesB[i].ID.entityID > max)
|
2020-06-18 01:04:08 +00:00
|
|
|
|
{
|
2020-11-09 21:18:25 +00:00
|
|
|
|
max = gamesB[i].ID.entityID;
|
2020-06-18 01:04:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool EnterGame(EGID id)
|
|
|
|
|
{
|
|
|
|
|
if (!ExistsGameInfo(id)) return false;
|
|
|
|
|
ref MyGameDataEntityStruct mgdes = ref GetGameInfo(id);
|
|
|
|
|
return EnterGame(mgdes.GameName, mgdes.SavedGamePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool EnterGame(string gameName, string path, ulong workshopId = 0uL, bool autoEnterSim = false)
|
|
|
|
|
{
|
|
|
|
|
GameMode.CurrentMode = autoEnterSim ? RCXMode.Play : RCXMode.Build;
|
|
|
|
|
GameMode.SaveGameDetails = new SaveGameDetails(gameName, path, workshopId);
|
|
|
|
|
// the private FullGameCompositionRoot.SwitchToGame() method gets passed to menu items for this reason
|
|
|
|
|
AccessTools.Method(typeof(FullGameCompositionRoot), "SwitchToGame").Invoke(FullGameFields.Instance, new object[0]);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetGameName(EGID id, string name)
|
|
|
|
|
{
|
|
|
|
|
if (!ExistsGameInfo(id)) return false;
|
|
|
|
|
GetGameInfo(id).GameName.Set(name);
|
2021-04-10 00:02:47 +00:00
|
|
|
|
//GetGameViewInfo(id).MyGamesSlotComponent.GameName = StringUtil.SanitiseString(name); - TODO: Input field struct
|
2020-06-18 01:04:08 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetGameDescription(EGID id, string name)
|
|
|
|
|
{
|
|
|
|
|
if (!ExistsGameInfo(id)) return false;
|
|
|
|
|
GetGameInfo(id).GameDescription.Set(name);
|
2021-04-10 00:02:47 +00:00
|
|
|
|
//GetGameViewInfo(id).MyGamesSlotComponent.GameDescription = StringUtil.SanitiseString(name); - TODO
|
2020-06-18 01:04:08 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsGameInfo(EGID id)
|
|
|
|
|
{
|
|
|
|
|
return entitiesDB.Exists<MyGameDataEntityStruct>(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ref MyGameDataEntityStruct GetGameInfo(EGID id)
|
|
|
|
|
{
|
|
|
|
|
return ref GetComponent<MyGameDataEntityStruct>(id);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-10 00:02:47 +00:00
|
|
|
|
/*public ref MyGamesSlotEntityViewStruct GetGameViewInfo(EGID id)
|
2020-08-07 17:55:00 +00:00
|
|
|
|
{
|
|
|
|
|
EntityCollection<MyGamesSlotEntityViewStruct> entities =
|
|
|
|
|
entitiesDB.QueryEntities<MyGamesSlotEntityViewStruct>(MyGamesScreenExclusiveGroups.GameSlotGuiEntities);
|
2020-11-09 21:18:25 +00:00
|
|
|
|
var entitiesB = entities.ToBuffer().buffer;
|
2020-08-07 17:55:00 +00:00
|
|
|
|
for (int i = 0; i < entities.count; i++)
|
|
|
|
|
{
|
2020-11-09 21:18:25 +00:00
|
|
|
|
if (entitiesB[i].ID.entityID == id.entityID)
|
2020-08-07 17:55:00 +00:00
|
|
|
|
{
|
2020-11-09 21:18:25 +00:00
|
|
|
|
return ref entitiesB[i];
|
2020-08-07 17:55:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MyGamesSlotEntityViewStruct[] defRef = new MyGamesSlotEntityViewStruct[1];
|
2021-04-10 00:02:47 +00:00
|
|
|
|
return ref defRef[0]; - TODO: The struct is internal now
|
|
|
|
|
}*/
|
2020-06-18 01:04:08 +00:00
|
|
|
|
|
2020-08-07 17:55:00 +00:00
|
|
|
|
public ref T GetComponent<T>(EGID id) where T: unmanaged, IEntityComponent
|
2020-06-18 01:04:08 +00:00
|
|
|
|
{
|
|
|
|
|
return ref entitiesDB.QueryEntity<T>(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class MyGameDataEntityDescriptor_DamnItFJWhyDidYouMakeThisInternal : GenericEntityDescriptor<MyGameDataEntityStruct> { }
|
|
|
|
|
}
|