jimmycushnie / jecs Goto Github PK
View Code? Open in Web Editor NEWJimmy's Epic Config System
License: Do What The F*ck You Want To Public License
Jimmy's Epic Config System
License: Do What The F*ck You Want To Public License
In Logic World, we're using SUCC for localization data. Since each language has a large number of localization keys, the data is split across multiple files for each language (i.e. English_UI.succ
, English_components.succ
ect).
Within our code, we're manually extracting the keys from each of these files and combining them into one giant dictionary. This functionality should be built-in to SUCC.
I think the ideal interface would be something like
new DistributedReadOnlyDataFile(params string[] path)
There should also be a constructor that takes an IReadOnlyList
As requested here is the issue to track this.
In the current LW beta all .succ files I have checked have content on the last line. While very minor is it generally good form to ensure at least one blank line at the end of a text file.
[Flags]
enum Flags
{
None = 0,
UnionJack = 1,
USA = 2,
Communist = 4,
SouthKorea = 8,
}
// ...
var file = new DataFile("example");
var communistBritain = Flags.UnionJack | Flags.Communist;
file.Set("flags", communistBritain);
example.succ
will contain the following:
flags: 5
It would be nicer if it contained something like this:
flags: UnionJack | Communist
or perhaps
flags: UnionJack, Communist
or maybe even
flags: UnionJack and Communist
Or maybe SUCC should support all three syntaxes, and the one that's used is a FileStyle
setting.
DataFile contains a FileSystemWatcher
. Currently there's no way to dispose of this manually.
the saving system is working when I am playing the game in the unity editor. But when I build my game and launch it, I get an error when it tries to make a data file. I think it is the wachter it tries to setup
line of code for making datafile: static DataFile Config = new DataFile("ProgramConfig");
error:
Uploading Crash Report
NotImplementedException: The method or operation is not implemented.
at System.IO.FileSystemWatcher..ctor (System.String path, System.String filter) [0x00006] in :0
at (wrapper remoting-invoke-with-check) System.IO.FileSystemWatcher..ctor(string,string)
at SUCC.DataFileBase.SetupWatcher () [0x0000d] in C:\Users\tfeij\Documents\Unity\The Kingdom\Assets\SUCC\SUCC\DataFiles\DataFileBase.cs:180
at SUCC.DataFileBase..ctor (System.String path, System.String defaultFile, System.Boolean autoReload) [0x000f8] in C:\Users\tfeij\Documents\Unity\The Kingdom\Assets\SUCC\SUCC\DataFiles\DataFileBase.cs:41
at SUCC.DataFile..ctor (System.String path, SUCC.FileStyle style, System.String defaultFile, System.Boolean autoSave, System.Boolean autoReload) [0x0000b] in C:\Users\tfeij\Documents\Unity\The Kingdom\Assets\SUCC\SUCC\DataFiles\DataFile.cs:39
at SUCC.DataFile..ctor (System.String path, System.String defaultFile, System.Boolean autoSave, System.Boolean autoReload) [0x00000] in C:\Users\tfeij\Documents\Unity\The Kingdom\Assets\SUCC\SUCC\DataFiles\DataFile.cs:29
at Game.DataSystem..cctor () [0x00000] in C:\Users\tfeij\Documents\Unity\The Kingdom\Assets\Scripts\SaveLoad\DataSystem.cs:8
Rethrow as TypeInitializationException: The type initializer for 'Game.DataSystem' threw an exception.
at Game.SavingSystem.Start () [0x00022] in C:\Users\tfeij\Documents\Unity\The Kingdom\Assets\Scripts\SaveLoad\SavingSystem.cs:19
Performance is not a focus of this project, but of course it'll ideally be as fast as possible, and ideally we never introduce any regressions to performance. To keep track of performance and in particular to track changes to performance across changes to the code, I intend to add a SUCC.Benchmarks
project. This project, a lovely companion to the existing SUCC.Tests
, will contain stress-testy benchmarks for various aspects of the library, including serialization and deserialization of all the different types, parsing files, and saving files.
We have GetAtPath, SetAtPath, and KeyExistsAtPath. Should also have an API for deleting data at a path
Current way:
MultiLineString: """
here is line one
here is line two
"""
There's really no need for the triple quotes. Desired:
MultiLineString:
here is line one
here is line two
Complications with this: the parser needs to use a more advanced method of detecting a multi-line string, so that it knows not to fail when those lines don't have a :
in them.
Parsing errors currently only tell you what kind of error happened. Sometimes they quote you the part of the file that caused the error. Every time a parsing error is thrown, the following information should be included:
Parsing errors should probably be their own kind of exception as well.
void Test()
{
var dicc = new Dictionary<int, Vector3>()
{
[22] = new Vector3(-12, 323, 432.43f),
[55] = new Vector3(-1, 0, 100),
[-100] = new Vector3(Mathf.PI, Mathf.PI, Mathf.PI),
};
var file = new DataFile("test", autoSave: true);
file.Set("dicc boi", dicc);
}
That code generates this file:
dicc boi:
22:
x: -12
y: 323
z: 432.43
55:
x: -1
y: 0
z: 100
-100:
x: 3.141593
y: 3.141593
z: 3.141593
Notice the key called "-100". Keys are not allowed to begin with -
, as that character is reserved for list nodes. Trying to read the file later will throw errors. This can also happen when using DataFile.SaveAsDictionary().
The solution is probably to allow -
in key nodes, and determine what is a list node by the absence of :
.
Files are currently generated with no trailing newline. This ought to be amended!
when I'm writing configuration files, they're often filled with numbers like 0.3333333333
and 1.1666666666
. It would be nice to be able to just write those as fractions, i.e. 1/3
and 7/6
.
When using the OnFileReloaded
callback in Unity apps, I pretty much always have to jump back to the main thread, since Unity doesn't let you do much from other threads. To save some code, SUCC should include a dispatcher, and there should be an additional event that dispatches the callback on the main thread automatically.
There should be some way of controlling which fields/properties of a type are saved even if you can't apply attributes to them.
probably the best way to do this is by treating them as nested arrays. A 2d array is saved the same was as an array of arrays, a 3d array is saved the same way as an array of arrays of arrays, ect
Internally, these use System.Nullable. SUCC should save the Value
property, and load it by using the constructor.
It is awkward to work with files which have very long strings without line breaks. There should be a way to break the line in the file without changing the returned string when it is loaded by SUCC.
One option is to have a character at the end of lines which tells the parser to ignore the line breaks.
Current:
Message: """
What the fuck did you just fucking say about me, you little bitch? I'll have you know I graduated top of my class in the Navy Seals, and I've been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I'm the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You're fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that's just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little "clever" comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn't, you didn't, and now you're paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You're fucking dead, kiddo.
"""
Desired:
Message: """
What the fuck did you just fucking say about me, you little bitch? \
I'll have you know I graduated top of my class in the Navy Seals, \
and I've been involved in numerous secret raids on Al-Quaeda, and \
I have over 300 confirmed kills. I am trained in gorilla warfare \
and I'm the top sniper in the entire US armed forces. You are nothing \
to me but just another target. I will wipe you the fuck out with \
precision the likes of which has never been seen before on this Earth, \
mark my fucking words. You think you can get away with saying that \
shit to me over the Internet? Think again, fucker. As we speak I am \
contacting my secret network of spies across the USA and your IP is \
being traced right now so you better prepare for the storm, maggot. \
The storm that wipes out the pathetic little thing you call your life. \
You're fucking dead, kid. I can be anywhere, anytime, and I can kill \
you in over seven hundred ways, and that's just with my bare hands. \
Not only am I extensively trained in unarmed combat, but I have \
access to the entire arsenal of the United States Marine Corps and \
I will use it to its full extent to wipe your miserable ass off the \
face of the continent, you little shit. If only you could have known \
what unholy retribution your little "clever" comment was about to bring \
down upon you, maybe you would have held your fucking tongue. But you \
couldn't, you didn't, and now you're paying the price, you goddamn idiot. \
I will shit fury all over you and you will drown in it. You're fucking \
dead, kiddo.
"""
There should be a version specifically for Godot Engine, which now supports c# bindings. The new version should use Godot's asset system for Default Files, and it should have a properly configured Default Path.
When using SUCC I often stumble across the issue, that it has been a few months and I forgot that one has to escape #
inside strings.
To my knowledge there are 3 types of strings:
<key>: <value>
<key>: "<value>"
<key>: """
<value>
"""
All three can be at any point be stopped with #
to start a comment. And \#
will place a #
into the content.
I understand that comments can and should be possible/escapable in one-line string values and block-string values.
But they just make no sense in quoted one line string. As after a comment, there is no possible way for the closing "
to be added. Hence it is basically destroying the value of the string.
One could argue, that the opening "
would be part of the message - but then that should be escaped, else it would be misleading.
If I am with my understanding correct, and the simple-quoted string is indeed limited to a single line.
Then my proposal is, to ignore #
inside of such string (as it makes no sense).
The core of this project was written when I was a much less seasoned programmer, and SUCC as a whole is not up to my current standards of code quality. Todo, at some point: refactor the whole damn thing.
I am pretty sure this is a compiler bug. It happens in the standalone c# version, but it does not happen with the Unity version.
static class Test
{
// this creates an empty file
static DataFile file = new DataFile("test"), defaultFileText: "# this is a test");
static void Main()
{
// this creates a file with the text "# this is a test"
var file = new DataFile("test2", defaultFileText: "# this is a test");
}
}
I have found through testing that the defaultFileText
variable is being set to null
before it reaches the constructor method.
It would be nice to have a compact way of writing collections. I.e.
collection:
- 22
- 10
- 35
- 0
shortcutCollection: [22, 10, 35, 0]
Careful consideration should be given to whatever syntax is chosen.
The main trouble is concurrency: if multiple "save file" commands are issued very quickly, they absolutely must be executed in the order they were called, lest outdated data be saved to disk
I was just weighing the pros and cons of INI or YAML for my upcoming game when I fell aware to SUCC.
I totally dig it!
Just one question; with all these variable options for indentation, how about tabs? Is it supported?
Currently the order members are listed in an apparently nondeterministic order, however in my experience it is almost always the derived class members and then the base class members, in the order the members are declared in the source file.
Order of saved members should be deterministic and reliable. The simplest way would be to do it alphabetically, but I would prefer to use the following rules. I am not sure if this is possible, but it's my ideal:
And perhaps we could have an attribute on members to customize their saving order.
Consider the following type.
struct Color
{
public byte r;
public byte g;
public byte b;
}
If we save it as SUCC, it will look something like this:
color:
r: 120
g: 142
b: 69
Now suppose later we make Color
a base type, saving and loading it as a hex code:
color: 788e45
At this point, SUCC will be unable to load the first example, as base types must ALWAYS be saved and loaded as their single-line value.
Proposal: if SUCC tries to load a node as a base type, and that node has child nodes, SUCC should treat the base type as a complex type.
Suppose we have the following file:
key : someValue # comment
key2 : shortValue # another comment lmao
If we edit the value of key2
to be longer, the file will now look like this:
key : someValue # comment
key2 : veryVeryLongValue # another comment lmao
This is obviously not ideal. When the user creates pretty file formatting, SUCC should do its best to preserve that prettiness when the data changes.
SUCC's tests were the first tests I ever wrote, and unfortunately I only discovered this Unit Testing Best Practices page after I finished them. All the tests should be refactored to conform to the best practices, and be very specific about what failed when there is a failure.
I.e. you should be able to save and load IEnumerable, ICollection, IReadOnlyList. Internally the library would just handle it like an array
SUCC does not support saving or loading interface types. This should be documented and it should throw an exception if you try.
Suppose I have the following class:
public class Color
{
public byte R, G, B;
public Color(byte r, byte g, byte b) => (R, G, B) = (r, g, b);
}
Currently, SUCC cannot deserialize this type, because it requires complex types to have a parameterless constructor. The system should be upgraded to check the constructor parameter names against the member names, and use those instead. Related: #14
Today I had to write 0.5333333333
. It would be much better to write 1/3 + 0.2
.
If a type has two constructors that take the same number of parameters, it chooses whichever comes first for use in constructor shortcuts.
class Example
{
public Example(int i)
{
}
public Example(string s)
{
}
}
if we try to use ("this is a string")
as a shortcut for an Example
, there will be an error as it will try to use the int shortcut. What should happen is that if there are multiple constructors with the same number of parameters, it keeps trying them until either there is no error or all constructors have been tried.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.