public int Create() { var KMap = Kthura.Create(); KMap.CreateLayer("__BASE"); return(Assign(KMap)); }
public int Load(string name) { try { var mappath = $"Maps/Kthura/{name.Trim()}/"; BubConsole.WriteLine($"Loading Kthura map {mappath}", 180, 0, 255); if (!(SBubble.JCR.Exists($"{mappath}Objects") && SBubble.JCR.Exists($"{mappath}Data"))) { SBubble.MyError("Kthura LoadMap Error", $"Error finding the two required files for map {name}", $"Found({mappath}Objects) => {SBubble.JCR.Exists($"{mappath}Objects")}\nFound({mappath}Data) => {SBubble.JCR.Exists($"{mappath}Data")}"); return(0); } var KMap = Kthura.Load(SBubble.JCR, mappath, SBubble.JCR); BubConsole.WriteLine($"Kthura map {mappath} loaded", 180, 0, 255); return(Assign(KMap)); } catch (Exception Ellende) { if (JCR6.JERROR != "") { Crash(JCR6.JERROR); } else { Crash(Ellende); } BubConsole.CSay(Ellende.StackTrace); return(0); } }
public static void PSave(Kthura map, string outfile, string prefix, string storage = "Store", string Author = "", string Notes = "") { var j = new TJCRCreate(outfile, storage); Save(map, j, prefix, storage, Author, Notes); j.Close(); }
public static void LetsGo() { #region Install Error Manager, and the global engine! NALACore.Core.Window.Title = SBubble.Title; #endregion #region The base MonoGame stuff SBubble.AddInit(delegate(string v) { SBubble.State(v).DoString($"function {FlowManager.NOTHING}() end", "Alright move along, nothing to see here!"); }); SBubble.AddInit(BubbleConsole.StateInit); SBubble.AddInit(BubbleGraphics.InitGraphics); SBubble.AddInit(Bubble_Audio.Init); SBubble.AddInit(APIFlow.Init); SBubble.AddInit(BubbleSuperGlobal.Init); SBubble.AddInit(Bubble_Input.Init); SBubble.AddInit(Bubble_Save.Init); SBubble.AddInit(Bubble_Conf.Init); SBubble.AddInit(Bubble_GameJolt.Init); SBubble.AddInit(BubbleTimer.Init); SBubble.AddInit(Bubble_Swap.Init); #endregion #region Extras to use in savegames Bubble_Save.SaveXtra["RPGPARTY"] = delegate(UseJCR6.TJCRCreate j, string dir) { RPG.RPGSave(j, $"XTRA/{dir}"); }; Bubble_Save.LoadXtra["RPGPARTY"] = delegate(UseJCR6.TJCRDIR j, string dir) { RPG.RPGLoad(j, $"XTRA/{dir}"); return(true); }; Bubble_Save.SaveXtra["SWAP"] = Bubble_Swap.SwapSave; Bubble_Save.LoadXtra["SWAP"] = Bubble_Swap.SwapLoad; #endregion #region The stuff needed for NALA in particular // Own APIs for NIL and Lua //SBubble.AddInit(MapScriptAPI.API_Init); SBubble.AddInit(RPG_API.Init); // Kthura Init Kthura.SetDefaultTextureJCR(SBubble.JCR); // Textures are all in the same project KthuraDraw.DrawDriver = new KthuraDrawMonoGame(); // Tell Kthura to use the MonoGame Driver to display the map KthuraDrawMonoGame.CrashOnNoTex = delegate(string msg) { SBubble.MyError("Kthura Texture Error", msg, ""); }; // SBubble Kthura API SBubble.AddInit(KthuraBubble.KthuraBubble.Init); SBubble.AddInit(KthuraBubble.KthBlockAPI.Init); SBubble.AddInit(KthuraBubble.KthuraAbyssGenerator.Init); // TODO: API for TeddyBear // TODO: API for Swap Data Manager // TODO: API for RPGStat RPG.JCRSTORAGE = "lzma"; #endregion // Start init script FlowManager.StartInitFlow(); }
public static void ComeToMe(HardFlowClass back, Kthura m, KthuraLayer l, int x, int y) { Map = m; MapLayer = l; ScrollX = x; ScrollY = y; ReturnFlow = back; FlowManager.GoHardFlow(Flow); time = 2500; }
public static void Save(Kthura map, TJCRCreate j, string prefix = "", string storage = "Store", string Author = "", string Notes = "") { if (Kthura.LoadUnknown) { foreach (var unk in map.Unknown) { System.Diagnostics.Debug.WriteLine($"Adding unknown {unk.Key} ({unk.Value.Length} bytes)"); j.AddBytes(unk.Value, unk.Key, storage, Author, Notes); } } j.NewStringMap(map.MetaData, $"{prefix}Data", storage, Author, Notes); j.AddString(GenObjects(map), $"{prefix}Objects", storage, Author, Notes); }
public override string DoExport(Kthura Map) { var ret = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF - 8\"?>\n"); ret.Append($"<!-- Generated by the Kthura Exporter (build:{BuildDate.sBuildDate}) -->\n\n"); ret.Append("<Kthura>\n"); foreach (string k in Map.MetaData.Keys) { ret.Append($"\t<MetaData key=\"{k}\" value=\"{Map.MetaData[k]}\" />\n"); } ret.Append("\t<LayerList>\n"); foreach (string k in Map.Layers.Keys) { ret.Append($"\t\t<lay>{k}</lay>\n"); } ret.Append("\t</LayerList>\n"); foreach (string k in Map.Layers.Keys) { var lay = Map.Layers[k]; ret.Append($"\n\t<Layer id=\"{k}\" grid=\"{lay.GridX}x{lay.GridY}\">\n"); foreach (KthuraObject obj in lay.Objects) { ret.Append("\t\t<Object\n"); ret.Append($"\t\t\tKind='{obj.kind}'\n"); ret.Append($"\t\t\tX='{obj.x}' Y='{obj.y}'\n"); ret.Append($"\t\t\tWidth='{obj.w}' Height='{obj.h}'\n"); ret.Append($"\t\t\tInsertX='{obj.insertx}' InsertY='{obj.inserty}'\n"); ret.Append($"\t\t\tTexture='{obj.Texture}'\n"); ret.Append($"\t\t\tVisible='{obj.Visible}'\n"); ret.Append($"\t\t\tScaleX='{obj.ScaleX}' ScaleY='{obj.ScaleY}'\n"); ret.Append($"\t\t\tRed='{obj.R}' Green='{obj.G}' Blue='{obj.B}'\n"); ret.Append($"\t\t\tAnimSpeed='{obj.AnimSpeed}' Frame='{obj.AnimFrame}'\n"); ret.Append($"\t\t\tDominance='{obj.Dominance}'\n"); ret.Append($"\t\t\tImpassible='{obj.Impassible}' ForcePassible='{obj.ForcePassible}'\n"); ret.Append($"\t\t\tTag='{obj.Tag}'>\n"); //ret.Append("\t\t>\n"); foreach (string mk in obj.MetaData.Keys) { ret.Append($"\t\t\t<data key='{mk}' value='{obj.MetaData[mk]}' />\n"); } ret.Append("\t\t</Object>\n"); } ret.Append("$\t</Layer>"); } ret.Append("</Kthura>"); return(ret.ToString()); }
int Assign(Kthura map) { int i = 0; do { i++; } while (KMaps.ContainsKey(i)); KMaps[i] = map; KScroll[i] = new BubKthScroll(); AutoRemap[i] = true; foreach (string first in map.Layers.Keys) { // Is there a better way? Layers[i] = first; break; } return(i); }
void Export(string amap) { if (amap == "") { foreach (string m in FileList.GetDir(Dirry.AD($"{MapDir}"))) { Export(m); } return; } var exporter = ExportBasis.Get(Target); var outputfile = $"{XPTo}/{exporter.ExportedFile(amap)}"; Kthura kmap = null; // (=null is required or the compiler THINKS we got an unassigned thing.... TRY it! :P Doing("Exporting Map", amap); Doing("Output", outputfile); Magenta(" Reading\r"); try { kmap = Kthura.Load($"{MapDir}/{amap}"); } catch (Exception e) { if (JCR6.JERROR != "" && JCR6.JERROR != "OK") { Error(JCR6.JERROR); } Error(e); } Assert(kmap != null, $"Failed to load the map! {JCR6.JERROR}"); Magenta(" Translating\r"); var translation = exporter.DoExport(kmap); Magenta(" Writing \r"); try { Directory.CreateDirectory(qstr.ExtractDir(outputfile)); QuickStream.SaveString(outputfile, translation); } catch (Exception e) { Error(e); } Magenta(" \n"); }
static string GenObjects(Kthura map) { StringBuilder ret = new StringBuilder(300000); // Header ret.Append($"-- Generated: {DateTime.Now.ToString()}, by Kthura for C#\n\n"); // Layer list ret.Append("LAYERS\n"); foreach (string lay in map.Layers.Keys) { ret.Append($"\t{lay}\n"); } ret.Append("__END\n\n"); // Layer head foreach (string lay in map.Layers.Keys) { var layer = map.Layers[lay]; ret.Append($"LAYER = {lay}\n\tGRID={layer.GridX}x{layer.GridY}\n"); foreach (KthuraObject obj in layer.Objects) { var vis = 0; if (obj.Visible) { vis = 1; } ret.Append($"\tNEW\n\t\tKIND = {obj.kind}\n\t\tCOORD = {obj.x},{obj.y}\n\t\tINSERT = {obj.insertx * (-1)},{obj.inserty * (-1)}\n\t\tROTATION = {obj.RotationDegrees}\n\t\tSIZE = {obj.w}x{obj.h}\n\t\tTAG = {obj.Tag}\n\t\tLABELS = {obj.Labels}\n\t\tDOMINANCE = {obj.Dominance}\n\t\tTEXTURE = {obj.Texture}\n\t\tCURRENTFRAME = {obj.AnimFrame}\n\t\tFRAMESPEED = {obj.AnimSpeed}\n\t\tALPHA = {(float)obj.Alpha1000 / 1000}\n\t\tVISIBLE = {vis}\n\t\tCOLOR = {obj.R}, {obj.G},{obj.B}\n\t\tIMPASSIBLE = {bl2bt[obj.Impassible]}\n\t\tFORCEPASSIBLE = {bl2bt[obj.ForcePassible]}\n\t\tSCALE = {obj.ScaleX},{obj.ScaleY}\n\t\tBLEND = 0\n"); foreach (string k in obj.MetaData.Keys) { ret.Append($"\t\t\tDATA.{k} = {obj.MetaData[k]}\n"); } } } return(ret.ToString()); }
public override string DoExport(Kthura Map) { var ret = new StringBuilder("{\n\n"); bool comma = false; bool comma2 = false; // Meta ret.Append("\t\"MetaData\" : {\n\t\t"); foreach (string key in Map.MetaData.Keys) { if (comma) { ret.Append(",\n\t\t"); } comma = true; ret.Append($"\"{key}\" : \"{Map.MetaData[key]}\""); } ret.Append("\t},\n\n"); // Layers comma = false; ret.Append("\t\"Layers\" : {\n"); foreach (string key in Map.Layers.Keys) { var lay = Map.Layers[key]; comma2 = false; if (comma) { ret.Append(",\n"); } comma = true; ret.Append($"\t\t\"{key}\" : {'{'}\n\t\t\t\"Grid\" : [{lay.GridX}, {lay.GridY}],\n\t\t\t\"Objects\" : [\n"); foreach (KthuraObject obj in lay.Objects) { if (comma2) { ret.Append(",\n"); } comma2 = true; ret.Append("\t\t\t\t{\n"); ret.Append($"\t\t\t\t\t'Kind' : '{obj.kind}',\n"); ret.Append($"\t\t\t\t\t'X' : {obj.x}, 'Y': {obj.y},\n"); ret.Append($"\t\t\t\t\t'Width' : {obj.w}, 'Height' : {obj.h},\n"); ret.Append($"\t\t\t\t\t'InsertX' : {obj.insertx}, 'InsertY' : {obj.inserty},\n"); ret.Append($"\t\t\t\t\t'Texture' : '{obj.Texture}',\n"); ret.Append($"\t\t\t\t\t'Visible' : '{obj.Visible}',\n"); ret.Append($"\t\t\t\t\t'ScaleX' : {obj.ScaleX}, 'ScaleY' : {obj.ScaleY},\n"); ret.Append($"\t\t\t\t\t'Red' : {obj.R}, 'Green' : {obj.G}, 'Blue' : {obj.B},\n"); ret.Append($"\t\t\t\t\t'AnimSpeed' : {obj.AnimSpeed}, 'Frame' : {obj.AnimFrame},\n"); ret.Append($"\t\t\t\t\t'Dominance' : {obj.Dominance},\n"); ret.Append($"\t\t\t\t\t'Impassible' : '{obj.Impassible}', 'ForcePassible' : '{obj.ForcePassible}',\n"); ret.Append($"\t\t\t\t\t'Tag' : '{obj.Tag}',\n"); ret.Append("\t\t\t\t\t'Data' : {\n"); var comma3 = false; foreach (string dkey in obj.MetaData.Keys) { if (comma3) { ret.Append(",\n"); } comma3 = true; ret.Append($"\t\t\t\t\t\t'{dkey}' : '{obj.MetaData[dkey]}'"); } ret.Append("\t\t\t\t\t}\n"); ret.Append("\t\t\t\t}"); } ret.Append("\n\t\t\t]"); ret.Append("\n\t\t}"); } ret.Append("\n\t}\n"); ret.Append("}"); return(ret.ToString()); }
static public bool IgnoreVisibility = false; // If set to true, invisible objects will still be shown. static public void DrawMap(Kthura map, string layer, int scrollx = 0, int scrolly = 0, int x = 0, int y = 0) => DrawMap(map.Layers[layer], scrollx, scrolly, x, y);
public override string DoExport(Kthura Map) { var ret = new StringBuilder("local ret = {\n\n"); bool comma = false; bool comma2 = false; // Meta ret.Append("\tMetaData = {\n\t\t"); foreach (string key in Map.MetaData.Keys) { if (comma) { ret.Append(",\n\t\t"); } comma = true; ret.Append($"[\"{key}\"] = \"{Map.MetaData[key]}\""); } ret.Append("\n\t},\n\n"); // Layers comma = false; ret.Append("\tLayers = {\n"); foreach (string key in Map.Layers.Keys) { var lay = Map.Layers[key]; comma2 = false; if (comma) { ret.Append(",\n"); } comma = true; ret.Append($"\t\t[\"{key}\"] = {'{'}\n\t\t\tGrid = {'{'}{lay.GridX}, {lay.GridY}{'}'},\n\t\t\tObjects = {'{'}\n"); foreach (KthuraObject obj in lay.Objects) { if (comma2) { ret.Append(",\n"); } comma2 = true; ret.Append("\t\t\t\t{\n"); ret.Append($"\t\t\t\t\tKind = '{obj.kind}',\n"); ret.Append($"\t\t\t\t\tX = {obj.x}, Y = {obj.y},\n"); ret.Append($"\t\t\t\t\tWidth = {obj.w}, Height = {obj.h},\n"); ret.Append($"\t\t\t\t\tInsertX = {obj.insertx}, InsertY = {obj.inserty},\n"); ret.Append($"\t\t\t\t\tTexture = '{obj.Texture}',\n"); ret.Append($"\t\t\t\t\tVisible = {obj.Visible.ToString().ToLower()},\n"); ret.Append($"\t\t\t\t\tScaleX = {obj.ScaleX}, ScaleY = {obj.ScaleY},\n"); ret.Append($"\t\t\t\t\tRed = {obj.R}, Green = {obj.G}, Blue = {obj.B},\n"); ret.Append($"\t\t\t\t\tAnimSpeed = {obj.AnimSpeed}, Frame = {obj.AnimFrame},\n"); ret.Append($"\t\t\t\t\tDominance = {obj.Dominance},\n"); ret.Append($"\t\t\t\t\tImpassible = {obj.Impassible.ToString().ToLower()}, ForcePassible = {obj.ForcePassible.ToString().ToLower()},\n"); ret.Append($"\t\t\t\t\tTag = '{obj.Tag}',\n"); ret.Append("\t\t\t\t\tData = {\n"); var comma3 = false; foreach (string dkey in obj.MetaData.Keys) { if (comma3) { ret.Append(",\n"); } comma3 = true; ret.Append($"\t\t\t\t\t\t['{dkey}'] = '{obj.MetaData[dkey]}'"); } ret.Append("\t\t\t\t\t}\n"); ret.Append("\t\t\t\t}"); } ret.Append("\n\t\t\t}"); ret.Append("\n\t\t}"); } ret.Append("\n\t}\n"); ret.Append("}\n\nreturn ret"); return(ret.ToString()); }
public override string DoExport(Kthura Map) => $"let KthuraMap = {Get("json").DoExport(Map)}";
public static void Save(Kthura map, string outfile, string storage = "Store", string Author = "", string Notes = "") => PSave(map, outfile, "", storage, Author, Notes);
TQMGImage GetTex(KthuraObject obj) { var file = obj.Texture; var kind = obj.kind; var lay = obj.Parent; var map = lay.Parent; var mfile = qstr.StripExt(file); if (qstr.ExtractExt(file.ToUpper()) == "PNG" && map.TextureJCR.Exists($"{mfile}.frames") && map.TextureJCR.DirExists($"{mfile}.jpbf")) { var rfile = $"{mfile}.jpbf"; switch (AutoBundle) { case TAutoBundle.Off: break; case TAutoBundle.AutomaticallyFixObject: obj.Texture = rfile; // Fallthrough... Otherwise not supported in C#, so this is the only way to do it (bad bad Microsoft) goto case TAutoBundle.ReplaceInLoadOnly; case TAutoBundle.ReplaceInLoadOnly: file = rfile; break; } } if (map != LastUsedMap) { Textures.Clear(); // Only store texture per map. Will take too much RAM otherwise! } LastUsedMap = map; var tag = $"{kind}::{file}"; if (!Textures.ContainsKey(tag)) { if (qstr.ExtractExt(file.ToUpper()) == "JPBF") { Textures[tag] = TQMG.GetBundle(map.TextureJCR, $"{file}/"); //Bubble.BubConsole.WriteLine($"KTHURA DRAW DEBUG: Loading Bundle {file}", 255, 255, 0); // debug! (must be on comment when not in use) } else { if (map.TextureJCR == null) { Debug.WriteLine("TextureJCR is null???"); } var bt = map.TextureJCR.ReadFile(file); if (bt == null) { if (NoTexture != null) { Textures[tag] = NoTexture; //TQMG.GetImage(NoTexture.GetTex(0)); System.Console.Beep(); Debug.WriteLine($"Texture {file} for {tag} could not be loaded , so set to alternet picture in stead ({UseJCR6.JCR6.JERROR})"); //return NoTexture; } else { CrashOnNoTex?.Invoke($"Couldn't open texture file {file} for {tag}"); Debug.WriteLine($"Couldn't open texture file {file} for {tag}"); return(null); } } else { Textures[tag] = TQMG.GetImage(bt); if (Textures[tag] == null) { if (NoTexture != null) { Textures[tag] = NoTexture; System.Console.Beep(); Debug.WriteLine($"Texture {tag} could not be loaded, so set to alternet picture in stead"); } else { CrashOnNoTex?.Invoke($"Texture `{file}` didn't load at all on tag {tag}.\n{UseJCR6.JCR6.JERROR}"); } } } } if (Textures[tag].Frames == 0) { CrashOnNoTex?.Invoke($"Texture `{file}` for tag `{tag}` has no frames"); } if (obj.kind == "Obstacle" || obj.kind == "Actor") { Textures[tag].HotBottomCenter(); } } return(Textures[tag]); }
public KthuraUsed(Kthura Map, TJCRDIR TexMap) { this.Map = Map; JCR = TexMap; Update(); }
public static void ComeToMe(HardFlowClass back, Kthura m, string l, int x, int y) => ComeToMe(back, m, m.Layers[l], x, y);
abstract public string DoExport(Kthura Map);