Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JujuAdams committed Oct 21, 2023
2 parents 913ca41 + e50798d commit 1db7bc0
Show file tree
Hide file tree
Showing 84 changed files with 475 additions and 99 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center"><img src="https://raw.githubusercontent.com/JujuAdams/SNAP/master/LOGO.png" style="display:block; margin:auto; width:300px"></p>
<h1 align="center">SNAP 5.8.1</h1>
<h1 align="center">SNAP 5.9.0</h1>

<p align="center">Data format converters for GameMaker Studio 2022 LTS by Juju Adams</p>

Expand Down
2 changes: 1 addition & 1 deletion objects/oTestBinary/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ struct = {
};

buffer = SnapBufferWriteBinary(ScratchBuffer(), struct);
show_debug_message(SnapToJSON(SnapBufferReadBinary(buffer, 0), true, true, true));
show_debug_message(SnapVisualize(SnapBufferReadBinary(buffer, 0)));
2 changes: 1 addition & 1 deletion objects/oTestConfigJSON/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ var _string = @"{
}";

var _json = SnapFromConfigJSON(_string);
show_debug_message(SnapToLooseJSON(_json, true, true, true));
show_debug_message(SnapVisualize(_json));
4 changes: 2 additions & 2 deletions objects/oTestDeepCopy/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ struct = {
func : function() { d += 1 },
};

show_debug_message(SnapToJSON(struct, true, true));
show_debug_message(SnapVisualize(struct));
copy = SnapDeepCopy(struct);
show_debug_message(SnapToJSON(copy, true, true));
show_debug_message(SnapVisualize(copy));
2 changes: 1 addition & 1 deletion objects/oTestGML/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct = {
};

show_debug_message(SnapToGML(struct, true));
show_debug_message(SnapToJSON(SnapFromGML(SnapToGML(struct, true)), true, true));
show_debug_message(SnapVisualize(SnapFromGML(SnapToGML(struct, true))));

var _string = @"
//Here's a comment
Expand Down
4 changes: 2 additions & 2 deletions objects/oTestINI/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ bool1 = 1
bool2 = on
bool3=f';

show_debug_message(SnapToJSON(SnapFromINIString(_text, false), true, true));
show_debug_message(SnapToJSON(SnapFromINIString(_text, true), true, true));
show_debug_message(SnapVisualize(SnapFromINIString(_text, false)));
show_debug_message(SnapVisualize(SnapFromINIString(_text, true)));
3 changes: 2 additions & 1 deletion objects/oTestLooseJSON/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ b: "2"
*/
c: /*oops*/3,
d: 4//done
}';
e: "string! //"';
_string += "\nf: @'multiline\n\nstring'\n}";

show_debug_message(SnapFromLooseJSON(_string));

Expand Down
2 changes: 1 addition & 1 deletion objects/oTestMerge/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ b = {
};

SnapMerge(b, a);
show_debug_message(SnapToJSON(a, true, true));
show_debug_message(SnapVisualize(a));
2 changes: 1 addition & 1 deletion objects/oTestMessagepack/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ struct = {

buffer = ScratchBuffer();
SnapBufferWriteMessagePack(buffer, struct);
show_debug_message(SnapToJSON(SnapBufferReadMessagePack(buffer, 0), true, true, true));
show_debug_message(SnapVisualize(SnapBufferReadMessagePack(buffer, 0)));
2 changes: 1 addition & 1 deletion objects/oTestQML/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ var _instanceofDict = {

var _string = SnapToQML(root, _instanceofDict);
show_debug_message(_string);
show_debug_message(SnapToJSON(SnapFromQML(_string, _instanceofDict), true, true, true));
show_debug_message(SnapVisualize(SnapFromQML(_string, _instanceofDict)));
show_debug_message(SnapToQML(SnapFromQML(_string, _instanceofDict), _instanceofDict));
4 changes: 2 additions & 2 deletions objects/oTestVDF/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ show_debug_message(SnapToVDF(struct, false, true));
show_debug_message("---------------------------------------------------------------------------------------");
show_debug_message(SnapToVDF(struct, true, true));
show_debug_message("---------------------------------------------------------------------------------------");
show_debug_message(SnapToJSON(SnapFromVDF("\"a\" { \"b\" \"c\" }"), true, true, true));
show_debug_message(SnapVisualize(SnapFromVDF("\"a\" { \"b\" \"c\" }")));
show_debug_message("---------------------------------------------------------------------------------------");
show_debug_message(SnapToJSON(SnapFromVDF(SnapToVDF(struct)), true, true, true));
show_debug_message(SnapVisualize(SnapFromVDF(SnapToVDF(struct))));
show_debug_message("---------------------------------------------------------------------------------------");
2 changes: 1 addition & 1 deletion objects/oTestXML/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ var _string = @'
</bookstore>';

var _struct = SnapFromXML(_string);
show_debug_message(SnapToJSON(_struct, true, true));
show_debug_message(SnapVisualize(_struct));
show_debug_message(SnapToXML(_struct, false));
show_debug_message(SnapToXML(_struct, true ));
2 changes: 1 addition & 1 deletion objects/oTestYAML/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct = {
show_debug_message("");
show_debug_message("--- Test 1 ---");
var _string = "{\"hello\" : \"world\", \"more\" : \"data\"}";
show_debug_message(SnapToJSON(SnapFromYAML(_string), true, true));
show_debug_message(SnapVisualize(SnapFromYAML(_string)));

show_debug_message("");
show_debug_message("--- Test 2 ---");
Expand Down
2 changes: 1 addition & 1 deletion options/windows/options_windows.yy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Windows",
"option_windows_display_name": "SNAP",
"option_windows_executable_name": "${project_name}.exe",
"option_windows_version": "5.8.1.0",
"option_windows_version": "5.9.0.0",
"option_windows_company_info": "@jujuadams",
"option_windows_product_info": "SNAP",
"option_windows_copyright_info": "@jujuadams 2023",
Expand Down
4 changes: 2 additions & 2 deletions rooms/rMain/rMain.yy
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
],
"layers": [
{"resourceType":"GMRInstanceLayer","resourceVersion":"1.0","name":"Instances","instances":[
{"resourceType":"GMRInstance","resourceVersion":"1.0","name":"inst_53BCBEF","properties":[],"isDnd":false,"objectId":{"name":"oTestVDF","path":"objects/oTestVDF/oTestVDF.yy",},"inheritCode":false,"hasCreationCode":false,"colour":4294967295,"rotation":0.0,"scaleX":1.0,"scaleY":1.0,"imageIndex":0,"imageSpeed":1.0,"inheritedItemId":null,"frozen":false,"ignore":false,"inheritItemSettings":false,"x":32.0,"y":32.0,},
{"resourceType":"GMRInstance","resourceVersion":"1.0","name":"inst_25D39681","properties":[],"isDnd":false,"objectId":{"name":"oTestXML","path":"objects/oTestXML/oTestXML.yy",},"inheritCode":false,"hasCreationCode":false,"colour":4294967295,"rotation":0.0,"scaleX":1.0,"scaleY":1.0,"imageIndex":0,"imageSpeed":1.0,"inheritedItemId":null,"frozen":false,"ignore":false,"inheritItemSettings":false,"x":32.0,"y":32.0,},
],"visible":true,"depth":0,"userdefinedDepth":false,"inheritLayerDepth":false,"inheritLayerSettings":false,"gridX":32,"gridY":32,"layers":[],"hierarchyFrozen":false,"effectEnabled":true,"effectType":null,"properties":[],},
{"resourceType":"GMRBackgroundLayer","resourceVersion":"1.0","name":"Background","spriteId":null,"colour":4278190080,"x":0,"y":0,"htiled":false,"vtiled":false,"hspeed":0.0,"vspeed":0.0,"stretch":false,"animationFPS":15.0,"animationSpeedType":0,"userdefinedAnimFPS":false,"visible":true,"depth":100,"userdefinedDepth":false,"inheritLayerDepth":false,"inheritLayerSettings":false,"gridX":32,"gridY":32,"layers":[],"hierarchyFrozen":false,"effectEnabled":true,"effectType":null,"properties":[],},
],
"inheritLayers": false,
"creationCodeFile": "",
"inheritCode": false,
"instanceCreationOrder": [
{"name":"inst_53BCBEF","path":"rooms/rMain/rMain.yy",},
{"name":"inst_25D39681","path":"rooms/rMain/rMain.yy",},
],
"inheritCreationOrder": false,
"sequenceId": null,
Expand Down
3 changes: 2 additions & 1 deletion scripts/ScratchBuffer/ScratchBuffer.gml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Feather disable all
function ScratchBuffer()
{
return buffer_create(1024, buffer_grow, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// Config struct should be in this format:
///
/// {
Expand Down Expand Up @@ -63,4 +64,4 @@ function Snap2DArrayToStructArray(_inputArray, _configStruct = {})
}

return _outputArray;
}
}
3 changes: 2 additions & 1 deletion scripts/SnapBufferRead2DArray/SnapBufferRead2DArray.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @param buffer
/// @param offset
///
Expand Down Expand Up @@ -36,4 +37,4 @@ function SnapBufferRead2DArray(_buffer, _inOffset)
if (_inOffset != undefined) buffer_seek(_buffer, buffer_seek_start, _oldOffset);

return _array;
}
}
3 changes: 2 additions & 1 deletion scripts/SnapBufferReadBOM/SnapBufferReadBOM.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// Attempts to read a UTF-8 byte order mark from a buffer, and returns <true> if a BOM is found
///
/// @param buffer Buffer to try to read the byte order mark from
Expand All @@ -17,4 +18,4 @@ function SnapBufferReadBOM(_buffer)
}

return false;
}
}
3 changes: 2 additions & 1 deletion scripts/SnapBufferReadBinary/SnapBufferReadBinary.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @return Nested struct/array data encoded from the buffer, using a proprietary format
///
/// @param buffer Binary data to be decoded, created by SnapBufferWriteBinary()
Expand Down Expand Up @@ -101,4 +102,4 @@ function __SnapFromBinaryValue(_buffer)
show_error("SNAP:\nUnsupported datatype " + string(buffer_peek(_buffer, buffer_u8, buffer_tell(_buffer)-1)) + " (position = " + string(buffer_tell(_buffer) - 1) + ")\n ", false);
break;
}
}
}
1 change: 1 addition & 0 deletions scripts/SnapBufferReadCSV/SnapBufferReadCSV.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// Decodes CSV data stored in a buffer and outputs a 2D array
///
/// @return 2D array that represents the contents of the CSV string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @return Nested struct/array data that represents the contents of the "Config JSON" string
///
/// @param buffer Buffer to read data from
Expand Down Expand Up @@ -659,4 +660,4 @@ function __SnapBufferReadConfigJSONDeepCopyInner(_value, _oldStruct, _newStruct)
}

return _copy;
}
}
3 changes: 2 additions & 1 deletion scripts/SnapBufferReadGML/SnapBufferReadGML.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @return Nested struct/array data that represents the contents of the JSON string. The root node will always be a struct
///
/// @param buffer The GML string to be decoded
Expand Down Expand Up @@ -507,4 +508,4 @@ function __SnapBufferReadGMLParser(_buffer, _buffer_size) constructor
}

read_root();
}
}
3 changes: 2 additions & 1 deletion scripts/SnapBufferReadGrid/SnapBufferReadGrid.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @param buffer
/// @param offset
///
Expand Down Expand Up @@ -33,4 +34,4 @@ function SnapBufferReadGrid(_buffer, _inOffset)
if (_inOffset != undefined) buffer_seek(_buffer, buffer_seek_start, _oldOffset);

return _grid;
}
}
5 changes: 3 additions & 2 deletions scripts/SnapBufferReadINI/SnapBufferReadINI.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @return Struct/array that represents the data in the INI file
///
/// N.B. That this script is only intended to read the .ini files that GM generates
Expand Down Expand Up @@ -104,8 +105,8 @@ function SnapBufferReadINI(_buffer, _offset, _size, _tryReal = true)
if (_value == ord("\"")) _in_string = true;
}

if (_value > 32) _last_non_whitespace = buffer_tell(_buffer) - 1;
if ((_value == 32) && (buffer_peek(_buffer, buffer_tell(_buffer) - 2, buffer_u8) == ord("\\"))) _last_non_whitespace = buffer_tell(_buffer) - 1;
if (_in_string || (_value > 32)) _last_non_whitespace = buffer_tell(_buffer) - 1;
if (!_in_string && (_value == 32) && (buffer_peek(_buffer, buffer_tell(_buffer) - 2, buffer_u8) == ord("\\"))) _last_non_whitespace = buffer_tell(_buffer) - 1;
if (_value == ord("\\")) _seen_backslash = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/SnapBufferReadJSON/SnapBufferReadJSON.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @return Nested struct/array data that represents the contents of the JSON string
///
/// @param buffer Buffer to read data from
Expand Down Expand Up @@ -499,4 +500,4 @@ function SnapBufferReadJSON(_buffer, _inOffset = undefined)
}

return _root;
}
}
43 changes: 42 additions & 1 deletion scripts/SnapBufferReadLooseJSON/SnapBufferReadLooseJSON.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @return Nested struct/array data that represents the contents of the "Loose JSON" string
///
/// @param buffer Buffer to read data from
Expand Down Expand Up @@ -253,6 +254,11 @@ function __SnapBufferReadLooseJSONValue(_buffer, _bufferSize, _firstByte)
{
return __SnapBufferReadLooseJSONDelimitedString(_buffer, _bufferSize);
}
else if ((_firstByte == ord("@")) && (buffer_peek(_buffer, buffer_tell(_buffer), buffer_u8) == ord("'")))
{
buffer_seek(_buffer, buffer_seek_relative, 1);
return __SnapBufferReadLooseJSONMultilineString(_buffer, _bufferSize);
}
else
{
return __SnapBufferReadLooseJSONString(_buffer, _bufferSize);
Expand Down Expand Up @@ -380,6 +386,41 @@ function __SnapBufferReadLooseJSONDelimitedString(_buffer, _bufferSize)
show_error("SNAP:\nFound unterminated string\n ", true);
}

function __SnapBufferReadLooseJSONMultilineString(_buffer, _bufferSize)
{
static _cacheBuffer = buffer_create(1024, buffer_grow, 1);
buffer_seek(_cacheBuffer, buffer_seek_start, 0);

var _start = buffer_tell(_buffer);
var _inString = false;

while(buffer_tell(_buffer) < _bufferSize)
{
var _byte = buffer_read(_buffer, buffer_u8);

if (_byte == ord("\""))
{
if ((buffer_peek(_buffer, buffer_tell(_buffer)-2, buffer_u8) != ord("\\"))
&& (buffer_peek(_buffer, buffer_tell(_buffer)-3, buffer_u8) != ord("\\")))
{
_inString = !_inString;
}
}
else if (!_inString && (_byte == ord("'")))
{
var _end = buffer_tell(_buffer)-1;
var _oldByte = buffer_peek(_buffer, _end, buffer_u8);
buffer_poke(_buffer, _end, buffer_u8, 0x00);
var _result = buffer_peek(_buffer, _start, buffer_string);
buffer_poke(_buffer, _end, buffer_u8, _oldByte);

return _result;
}
}

show_error("SNAP:\nFound unterminated multiline string\n ", true);
}

function __SnapBufferReadLooseJSONString(_buffer, _bufferSize)
{
static _cacheBuffer = buffer_create(1024, buffer_grow, 1);
Expand Down Expand Up @@ -614,4 +655,4 @@ function __SnapBufferReadLooseJSONDeepCopyInner(_value, _oldStruct, _newStruct)
}

return _copy;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @return Nested struct/array data decoded from the buffer, using the messagepack standard
///
/// More information on messagepack can be found here: https://msgpack.org/index.html
Expand Down Expand Up @@ -219,4 +220,4 @@ function __SnapFromMessagepackLittleEndian(_buffer, _datatype)
}

return buffer_peek(_flipBuffer, 0, _datatype);
}
}
1 change: 1 addition & 0 deletions scripts/SnapBufferReadNSV/SnapBufferReadNSV.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// Decodes an NSV buffer and outputs a 2D array
///
/// @return 2D array that represents the contents of the NSV buffer
Expand Down
1 change: 1 addition & 0 deletions scripts/SnapBufferReadQML/SnapBufferReadQML.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Feather disable all
/// @return Nested struct/array data that represents the contents of the QML string
///
/// @param buffer Buffer to read data from
Expand Down
16 changes: 12 additions & 4 deletions scripts/SnapBufferReadTilemapNew/SnapBufferReadTilemapNew.gml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/// @param buffer
/// @param offset
/// @param layer
// Feather disable all
/// Creates a new tilemap on the given layer. The tilemap's dimensions and position will be set to
/// whatever is in the data found in the buffer. If you do **not** specify an offset then SNAP will
/// modify the buffer's "head" position. This allows you to read sequential data more easily.
///
/// N.B. The name of the tileset to use is embedded in the tilemap data so any renamed or
/// deleted tilesets will fail to read.
///
/// @param buffer Buffer to write the data into
/// @param offset The position in the buffer to read the tilemap from, relative to the start of the buffer. If set to <undefined>, the buffer's head position is used
/// @param layer Name of room layer to create the tilemap on
///
/// @jujuadams 2023-04-25

Expand Down Expand Up @@ -40,4 +48,4 @@ function SnapBufferReadTilemapNew(_buffer, _inOffset, _layer)
}

if (_inOffset != undefined) buffer_seek(_buffer, buffer_seek_start, _oldOffset);
}
}
Loading

0 comments on commit 1db7bc0

Please sign in to comment.