Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Fixes to Read and Write Metadata APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Dec 16, 2019
1 parent d94b952 commit f6391e6
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Disks/RunnerTools/ErrorTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end
-- Set the background an rebuild the screen buffer
BackgroundColor(tonumber(ReadBiosData("DefaultBackgroundColor", "5")))

local message = ReadMetaData("errorMessage")
local message = ReadMetadata("errorMessage")

local display = Display()

Expand Down
4 changes: 2 additions & 2 deletions Disks/RunnerTools/LoadTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ function Init()
-- Set the background an rebuild the screen buffer
BackgroundColor(tonumber(ReadBiosData("DefaultBackgroundColor", "5")))

if(ReadMetaData("showEjectAnimation") == "true") then
if(ReadMetadata("showEjectAnimation") == "true") then
currentAnimation = ejectAnimation
mode = "ejecting"
totalFrames = #currentAnimation
loopKeyframe = totalFrames - 2
elseif(ReadMetaData("showDiskAnimation") == "true") then
elseif(ReadMetadata("showDiskAnimation") == "true") then
mode = "inserting"
currentAnimation = insertAnimation
totalFrames = #currentAnimation
Expand Down
20 changes: 10 additions & 10 deletions Runners/PixelVision8/Runner/Editors/GameEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void Save(string path, SaveFlags[] flags)

for (var i = 0; i < flags.Length; i++) saveFlags |= flags[i];

targetGame.SetMetaData("version", runner.systemVersion);
targetGame.SetMetadata("version", runner.systemVersion);
// gameChip.version = ;

// TODO saving games doesn't work
Expand Down Expand Up @@ -408,13 +408,13 @@ public string Name(string name = null)
// If a new name is supplied, set it on the game chip
if (name != null)
{
targetGame.GetMetaData("name", name);
targetGame.GetMetadata("name", name);
Invalidate();
}


// Return the latest name value from the gameChip
return targetGame.GetMetaData("name", GetType().Name);
return targetGame.GetMetadata("name", GetType().Name);
}

/// <summary>
Expand All @@ -423,18 +423,18 @@ public string Name(string name = null)
/// <returns></returns>
public string Version()
{
return targetGame.GetMetaData("version", runner.systemVersion);
return targetGame.GetMetadata("version", runner.systemVersion);
}

public string Ext(string value = null)
{
if (value != null)
{
targetGame.SetMetaData("ext", value);
targetGame.SetMetadata("ext", value);
Invalidate();
}

return targetGame.GetMetaData("ext", ".pv8");
return targetGame.GetMetadata("ext", ".pv8");
}

public int BackgroundColor(int? id = null)
Expand Down Expand Up @@ -1284,14 +1284,14 @@ public string SaveFont(string fontName)
return fontPath.EntityName;
}

public string ReadMetaData(string key, string defaultValue = "")
public string ReadMetadata(string key, string defaultValue = "")
{
return targetGame.GetMetaData(key, defaultValue);
return targetGame.GetMetadata(key, defaultValue);
}

public void WriteMetaData(string key, string value)
public void WriteMetadata(string key, string value)
{
targetGame.SetMetaData(key, value);
targetGame.SetMetadata(key, value);
}


Expand Down
10 changes: 8 additions & 2 deletions Runners/PixelVision8/Runner/PixelVision8Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,15 @@ public override void RunGame()

// Make sure we stop recording when loading a new game
if (recording) StopRecording();

if (newMode == RunnerMode.Loading && metaData != null)
if (newMode == RunnerMode.Loading)
{
// Create metadata if it doesn't exists so we can store the eject value for the loader
if (metaData == null)
{
metaData = new Dictionary<string, string>();
}

// Tell the loader to show eject animation
if (metaData.ContainsKey("showEjectAnimation"))
metaData["showEjectAnimation"] = ejectingDisk.ToString().ToLower();
Expand Down
43 changes: 26 additions & 17 deletions SDK/Engine/Chips/Game/GameChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,10 +1385,10 @@ public void StopSong()
/// <param name="position">
/// Position in the loop to start playing at.
/// </param>
/// <param name="loopID">
/// <param name="patternID">
/// The loop to rewind too.
/// </param>
public void RewindSong(int position = 0, int loopID = 0)
public void RewindSong(int position = 0, int patternID = 0)
{
//TODO need to add in better support for rewinding a song across multiple loops
musicChip.RewindSong();
Expand Down Expand Up @@ -1817,15 +1817,15 @@ public void GetCachedPixels(int x, int y, int blockWidth, int blockHeight, ref i
// Invalidate();
}

public void ReadPixelData(int width, int height, ref int[] pixelData, int offsetX = 0, int offsetY = 0)
{
// Test if we need to rebuild the cached tilemap
if (tilemapChip.invalid)
RebuildCache(cachedTileMap);

// Return the requested pixel data
cachedTileMap.CopyPixels(ref pixelData, offsetX, offsetY, width, height);
}
// public void ReadPixelData(int width, int height, ref int[] pixelData, int offsetX = 0, int offsetY = 0)
// {
// // Test if we need to rebuild the cached tilemap
// if (tilemapChip.invalid)
// RebuildCache(cachedTileMap);
//
// // Return the requested pixel data
// cachedTileMap.CopyPixels(ref pixelData, offsetX, offsetY, width, height);
// }

private int[] tilemapCachePixels;

Expand Down Expand Up @@ -2067,10 +2067,10 @@ public int[] BitArray(int value)
/// </summary>
/// <param name="paletteID">The palette number, 1 - 8</param>
/// <returns></returns>
public int PaletteOffset(int paletteID, int paletteColor = 0)
public int PaletteOffset(int paletteID, int paletteColorID = 0)
{
// TODO this is hardcoded right now but there are 8 palettes with a max of 16 colors each
return 128 + Clamp(paletteID, 0, 7) * 16 + Clamp(paletteColor, 0, ColorsPerSprite() - 1);
return 128 + Clamp(paletteID, 0, 7) * 16 + Clamp(paletteColorID, 0, ColorsPerSprite() - 1);
}

public struct MetaSpriteData
Expand Down Expand Up @@ -2203,19 +2203,28 @@ public void DeleteMetaSprite(string name)
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public string ReadMetaData(string key, string defaultValue = "undefined")
public string ReadMetadata(string key, string defaultValue = "undefined")
{
return engine.GetMetaData(key, defaultValue);
return engine.GetMetadata(key, defaultValue);
}

/// <summary>
/// Writes meta data back into the game which can be read if the game reloads.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void WriteMetaData(string key, string value)
public void WriteMetadata(string key, string value)
{
engine.SetMetaData(key, value);
engine.SetMetadata(key, value);
}

public Dictionary<string, string> ReadAllMetadata()
{
var tmpMetadata = new Dictionary<string, string>();

engine.ReadAllMetadata(tmpMetadata);

return tmpMetadata;
}

#endregion
Expand Down
5 changes: 3 additions & 2 deletions SDK/Engine/Chips/Game/LuaGameChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ public override void Reset()
luaScript.Globals["LoadScript"] = new Action<string>(LoadScript);
luaScript.Globals["ReadSaveData"] = new Func<string, string, string>(ReadSaveData);
luaScript.Globals["WriteSaveData"] = new Action<string, string>(WriteSaveData);
luaScript.Globals["ReadMetaData"] = new Func<string, string, string>(ReadMetaData);
luaScript.Globals["WriteMetaData"] = new Action<string, string>(WriteMetaData);
luaScript.Globals["ReadMetadata"] = new Func<string, string, string>(ReadMetadata);
luaScript.Globals["WriteMetadata"] = new Action<string, string>(WriteMetadata);
luaScript.Globals["ReadAllMetadata"] = new Func< Dictionary<string, string>>(ReadAllMetadata);

#endregion

Expand Down
34 changes: 17 additions & 17 deletions SDK/Engine/Chips/Input/ControllerChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void RegisterKeyInput()

var player1 = getPlayer(0);

var test = engine.GetMetaData(InputMap.Player1UpKey.ToString());
var test = engine.GetMetadata(InputMap.Player1UpKey.ToString());
// Console.WriteLine("Key test up - "+test + " - " + InputMap.Player1UpKey.ToString());
//(Keys) Enum.Parse(typeof(Keys),
// player1.GamePadIndex = KEYBOARD_INDEX;
Expand All @@ -254,58 +254,58 @@ public void RegisterKeyInput()
{
player1.KeyboardMap = new Dictionary<Buttons, Keys>
{
{Buttons.Up, (Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player1UpKey.ToString()))},
{Buttons.Up, (Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player1UpKey.ToString()))},
{
Buttons.Left,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player1LeftKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player1LeftKey.ToString()))
},
{
Buttons.Right,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player1RightKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player1RightKey.ToString()))
},
{
Buttons.Down,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player1DownKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player1DownKey.ToString()))
},
{
Buttons.Select,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player1SelectKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player1SelectKey.ToString()))
},
{
Buttons.Start,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player1StartKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player1StartKey.ToString()))
},
{Buttons.A, (Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player1AKey.ToString()))},
{Buttons.B, (Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player1BKey.ToString()))}
{Buttons.A, (Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player1AKey.ToString()))},
{Buttons.B, (Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player1BKey.ToString()))}
};

var player2 = getPlayer(1);
// player2.GamePadIndex = KEYBOARD_INDEX;
player2.KeyboardMap = new Dictionary<Buttons, Keys>
{
{Buttons.Up, (Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player2UpKey.ToString()))},
{Buttons.Up, (Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player2UpKey.ToString()))},
{
Buttons.Left,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player2LeftKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player2LeftKey.ToString()))
},
{
Buttons.Right,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player2RightKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player2RightKey.ToString()))
},
{
Buttons.Down,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player2DownKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player2DownKey.ToString()))
},
{
Buttons.Select,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player2SelectKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player2SelectKey.ToString()))
},
{
Buttons.Start,
(Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player2StartKey.ToString()))
(Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player2StartKey.ToString()))
},
{Buttons.A, (Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player2AKey.ToString()))},
{Buttons.B, (Keys) Enum.Parse(typeof(Keys), engine.GetMetaData(InputMap.Player2BKey.ToString()))}
{Buttons.A, (Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player2AKey.ToString()))},
{Buttons.B, (Keys) Enum.Parse(typeof(Keys), engine.GetMetadata(InputMap.Player2BKey.ToString()))}
};
}
catch (Exception e)
Expand Down
6 changes: 3 additions & 3 deletions SDK/Engine/IEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ public interface IEngine : IEngineChips, IUpdate, IDraw
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
string GetMetaData(string key, string defaultValue = "");
string GetMetadata(string key, string defaultValue = "");

/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
void SetMetaData(string key, string value);
void SetMetadata(string key, string value);

/// <summary>
/// </summary>
/// <param name="target"></param>
/// <param name="ignoreKeys"></param>
void DumpMetaData(Dictionary<string, string> target, string[] ignoreKeys = null);
void ReadAllMetadata(Dictionary<string, string> target);
}
}
9 changes: 4 additions & 5 deletions SDK/Engine/PixelVisionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public virtual void Shutdown()
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public string GetMetaData(string key, string defaultValue = "")
public string GetMetadata(string key, string defaultValue = "")
{
if (!_metaData.ContainsKey(key))
_metaData.Add(key, defaultValue);
Expand All @@ -215,7 +215,7 @@ public string GetMetaData(string key, string defaultValue = "")
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void SetMetaData(string key, string value)
public void SetMetadata(string key, string value)
{
if (!_metaData.ContainsKey(key))
{
Expand All @@ -234,13 +234,12 @@ public void SetMetaData(string key, string value)
/// </summary>
/// <param name="target"></param>
/// <param name="ignoreKeys"></param>
public void DumpMetaData(Dictionary<string, string> target, string[] ignoreKeys)
public void ReadAllMetadata(Dictionary<string, string> target)
{
target.Clear();

foreach (var data in _metaData)
if (Array.IndexOf(ignoreKeys, data.Key) == -1)
target.Add(data.Key, data.Value);
target.Add(data.Key, data.Value);
}


Expand Down
14 changes: 12 additions & 2 deletions SDK/Runner/DesktopRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,24 @@ public override void ActivateEngine(IEngine engine)
{
// Console.WriteLine("History " + loadHistory.Last().Key + " " + path);
// Only add the history if the last item is not the same

// Loop through the history and see if the path already exists
for (int i = loadHistory.Count-1; i >= 0 ; i--)
{
if (loadHistory[i].Key == path)
{
loadHistory.RemoveAt(i);
}
}

if (loadHistory.Last().Key != path)
loadHistory.Add(new KeyValuePair<string, Dictionary<string, string>>(path, metaDataCopy));
}
else
{
loadHistory.Add(new KeyValuePair<string, Dictionary<string, string>>(path, metaDataCopy));
}
}
}

// Create a new tmpEngine
ConfigureEngine(metaData);
Expand Down Expand Up @@ -490,7 +500,7 @@ protected override void ConfigureKeyboard()

var keyValue = rawValue;

tmpEngine.SetMetaData(keyMap.Key.ToString(), keyValue.ToString());
tmpEngine.SetMetadata(keyMap.Key.ToString(), keyValue.ToString());
}

tmpEngine.controllerChip.RegisterKeyInput();
Expand Down
4 changes: 2 additions & 2 deletions SDK/Runner/GameRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public virtual void ConfigureEngine(Dictionary<string, string> metaData = null)
// Pass all meta data into the engine instance
if (metaData != null)
foreach (var entry in metaData)
tmpEngine.SetMetaData(entry.Key, entry.Value);
tmpEngine.SetMetadata(entry.Key, entry.Value);

ConfigureKeyboard();

Expand All @@ -481,7 +481,7 @@ protected virtual void ConfigureKeyboard()

var keyValue = rawValue;

tmpEngine.SetMetaData(keyMap.Key.ToString(), keyValue.ToString());
tmpEngine.SetMetadata(keyMap.Key.ToString(), keyValue.ToString());
}

tmpEngine.controllerChip.RegisterKeyInput();
Expand Down

0 comments on commit f6391e6

Please sign in to comment.