Skip to content

Commit

Permalink
Add readme and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Oct 30, 2019
1 parent dd28724 commit a7612a8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ wsf-test-*
*.obj
*.lst
dub.selections.json
test.bin
test.bin
test.wsf
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# WereShift Format
A D binary serialization format made for the game "Wereshift".
It can be used elsewhere as a small binary format.


## Parsing file
```d
Tag data = Tag.parseFile("file.wsf");
writeln(data["foo"]);
writeln(data.seq[0]);
```

## Building file
```d
Tag myData = Tag.emptyCompound();
myData["foo"] = "bar";
myData.seq ~= new Tag("baz");
// Note: this will overwrite the contents of the file
myData.buildFile("file.wsf");
```

## Notes
TODO
* Memory based streams
* Proper struct/class serialization via interface
* C interface(?)
4 changes: 2 additions & 2 deletions source/wsf/ast/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import std.stdio;
unittest {
Tag myTag = Tag.emptyCompound();
myTag["test"] = "Test";
myTag.buildFile("test.bin");
myTag.buildFile("test.wsf");

Tag readTag = Tag.parseFile("test.bin");
Tag readTag = Tag.parseFile("test.wsf");
assert(myTag["test"] != readTag["test"], "Tags did not match!");
}
6 changes: 5 additions & 1 deletion source/wsf/ast/tag.d
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ public:
*/
void opOpAssign(string op = "~=", T)(T value) {
if (kind == TagKind.array_) {
this.value.array_Value ~= new Tag(value);
static if (is (T : Tag)) {
this.value.array_Value ~= value;
} else {
this.value.array_Value ~= new Tag(value);
}
}
static if (is(T : string)) {
if (kind == TagKind.string_) {
Expand Down
8 changes: 8 additions & 0 deletions source/wsf/spec/scene.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@

// Copyright Luna & Cospec 2019.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

module wsf.spec.scene;

// TODO: Implement

class Scene {

}

0 comments on commit a7612a8

Please sign in to comment.