Skip to content

Commit

Permalink
Merge branch 'v3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
keiwando committed Sep 20, 2019
2 parents 95dad50 + d7bcc32 commit a4a5b4b
Show file tree
Hide file tree
Showing 1,400 changed files with 116,941 additions and 147,690 deletions.
38 changes: 20 additions & 18 deletions .vs/Evolution/xs/UserPrefs.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
<Properties StartupConfiguration="{6B6A62CD-8865-7A37-6813-2674E59EA488}|">
<MonoDevelop.Ide.ItemProperties.Evolution PreferredExecutionTarget="Unity.Editor" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/Scripts/ButtonManager.cs">
<Properties StartupConfiguration="{3D4C3948-95AB-35D4-8403-2BDCFF7854FF}|">
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/Scripts/Settings/Settings.cs">
<Files>
<File FileName="Assets/Scripts/evolution-core/Body/Muscle.cs" Line="205" Column="101" />
<File FileName="Assets/Scripts/Brains/RunningBrain.cs" Line="24" Column="3" />
<File FileName="Assets/Scripts/evolution-core/Evolution.cs" Line="404" Column="20" />
<File FileName="Assets/Scripts/evolution-core/Creature.cs" Line="462" Column="32" />
<File FileName="Assets/Scripts/evolution-core/Brain/Brain.cs" Line="435" Column="6" />
<File FileName="Assets/Scripts/evolution-core/Body/Joint.cs" Line="86" Column="2" />
<File FileName="Assets/Scripts/evolution-core/Body/Bone.cs" Line="88" Column="1" />
<File FileName="Assets/Scripts/evolution-core/Body/MuscleJoint.cs" Line="35" Column="3" />
<File FileName="Assets/Scripts/evolution-core/View/SimulationLoadDialog.cs" Line="9" Column="39" />
<File FileName="Assets/Scripts/ButtonManager.cs" Line="66" Column="42" />
<File FileName="Assets/Scripts/evolution-core/View/AndroidBackButtonMenuController.cs" Line="26" Column="35" />
<File FileName="Assets/Scripts/evolution-core/View/AutoScroll.cs" Line="25" Column="26" />
<File FileName="Assets/Scripts/evolution-core/View/SaveDialog.cs" Line="16" Column="2" />
<File FileName="Assets/Scripts/CreatureBuilder.cs" Line="841" Column="36" />
<File FileName="Assets/Scripts/Controllers/SimulationFileManager.cs" Line="17" Column="2" />
<File FileName="Assets/Scripts/View/ListLayoutGroup.cs" Line="23" Column="19" />
<File FileName="Assets/Scripts/View/ButtonManager.cs" Line="73" Column="16" />
<File FileName="Assets/Scripts/Controllers/CreatureBuilder.cs" Line="760" Column="53" />
<File FileName="Assets/Scripts/Saving/CreatureSaver.cs" Line="330" Column="40" />
<File FileName="Assets/Scripts/View/FileSelectionViewController.cs" Line="56" Column="44" NotebookId="1" />
<File FileName="Assets/Scripts/View/ViewController.cs" Line="70" Column="8" NotebookId="1" />
<File FileName="Assets/Scripts/View/SimulationLoadDialog.cs" Line="47" Column="56" NotebookId="1" />
<File FileName="Assets/Scripts/Saving/SimulationSerializer.cs" Line="428" Column="23" NotebookId="1" />
<File FileName="Assets/Scripts/View/SelectableListItemView.cs" Line="20" Column="2" NotebookId="1" />
<File FileName="Assets/Scripts/Controllers/CreatureFileManager.cs" Line="29" Column="39" NotebookId="1" />
<File FileName="Assets/Scripts/View/CreatureDesignControlsView.cs" Line="16" Column="45" NotebookId="1" />
<File FileName="Assets/Scripts/Settings/PlayerPrefsKeys.cs" Line="1" Column="1" NotebookId="1" />
<File FileName="Assets/Scripts/Settings/SettingsMenu.cs" Line="1" Column="1" NotebookId="1" />
<File FileName="Assets/Scripts/Settings/Settings.cs" Line="28" Column="3" NotebookId="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<MonoDevelop.Ide.ItemProperties.Evolution PreferredExecutionTarget="Unity.Editor" />
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.ItemProperties.Assembly-CSharp PreferredExecutionTarget="Unity.Editor" />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<MultiItemStartupConfigurations />
</Properties>
Binary file modified .vs/Evolution/xs/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/Evolution/xs/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/Evolution/xs/sqlite3/storage.ide-wal
Binary file not shown.
39 changes: 39 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Unity Editor",
"type": "unity",
"path": "/Users/Keiwan/Projects/Unity/Evolution/Library/EditorInstance.json",
"request": "launch"
},
{
"name": "Windows Player",
"type": "unity",
"request": "launch"
},
{
"name": "OSX Player",
"type": "unity",
"request": "launch"
},
{
"name": "Linux Player",
"type": "unity",
"request": "launch"
},
{
"name": "iOS Player",
"type": "unity",
"request": "launch"
},
{
"name": "Android Player",
"type": "unity",
"request": "launch"
}
]
}
193 changes: 193 additions & 0 deletions Assets/Editor/SettingsGen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;

public class SettingsGen {

/// <summary>
/// The path to the settings file to be parsed relative to the root of
/// the assets directory.
/// </summary>
private const string INPUT_PATH = "Scripts/Data/settings.txt";
/// <summary>
/// The path to the directory that the generated .cs file should be written
/// to.
/// </summary>
/// <remarks> An existing file with the same name will be overwritten!</remarks>
private const string OUTPUT_DIR = "Scripts/Data";
/// <summary>
/// The name of the generated C# class.
/// </summary>
private const string OUTPUT_CLASS_NAME = "Settings";

private static readonly Regex PARSING_PATTERN =
new Regex(@"(bool|string|int|float) ([\w\d_]+);?( ?= ?([^; ]+);?)?( ?\(([^)]+)\);?)?");

private static readonly Regex UPPERCACSE_PATTERN = new Regex("[A-Z]+|[0-9]+");

private const string IMPORTS = "using UnityEngine;";
private const string HELPERS = @" private static bool GetBool(string key, bool defaultValue = false) {
return PlayerPrefs.GetInt(key, defaultValue ? 1 : 0) == 1;
}
private static void SetBool(string key, bool b) {
PlayerPrefs.SetInt(key, b ? 1 : 0);
PlayerPrefs.Save();
}
public static void Save() {
PlayerPrefs.Save();
}
public static void Reset() {
PlayerPrefs.DeleteAll();
Initialize();
}";

[MenuItem("Tools/SettingsGen/Generate")]
public static void Generate() {

var inputPath = Path.Combine(Application.dataPath, INPUT_PATH);
var outputPath = Path.Combine(Application.dataPath, OUTPUT_DIR);
outputPath = Path.Combine(outputPath, string.Format("{0}.cs", OUTPUT_CLASS_NAME));

var keyDeclarations = new List<string>();
var properties = new List<string>();
var initializations = new List<string>();

var lines = new List<string>(File.ReadAllLines(inputPath));
foreach (var line in lines) {
if ("".Equals(line)) { continue; }

var match = PARSING_PATTERN.Match(line);
if (match.Success) {

var groups = match.Groups;
var type = groups[1].Value;
var propName = groups[2].Value;
var init = groups[4].Success ? groups[4].Value : null;
var forcedKey = groups[6].Success ? groups[6].Value : null;

properties.Add(ToProperty(propName, type, init));
keyDeclarations.Add(ToKeyMember(propName, forcedKey));

if (init != null) {
initializations.Add(string.Format("{0} = {1};", propName, init));
}

} else {
Debug.Log(string.Format("Invalid line: {0}", line));
}
}

var builder = new StringBuilder();
builder.AppendLine(IMPORTS);
builder.AppendLine("");
builder.AppendLine(string.Format("public class {0} {{", OUTPUT_CLASS_NAME));
builder.AppendLine("");
foreach (var keyInit in keyDeclarations) {
builder.AppendLine(keyInit);
}
builder.AppendLine("");
foreach (var prop in properties) {
builder.AppendLine(prop);
builder.AppendLine("");
}
builder.AppendLine(CreateInitializer(initializations));
builder.AppendLine(HELPERS);
builder.AppendLine("}");

var fileInfo = new FileInfo(outputPath);
if (!fileInfo.Exists)
Directory.CreateDirectory(fileInfo.Directory.FullName);

File.WriteAllText(outputPath, builder.ToString());
}

private static string CreateInitializer(List<string> initializations) {

// Decrease the potential of this initialization flag being used as a settings
// key
// Use a constant random string that doesn't get regenerated each time
var uuid = "e31cf645-7751-4a7b-ae0d-2ca38f6063b8"; //System.Guid.NewGuid().ToString();
var firstTimeKey = string.Format("ALREADY_INITIALIZED_{0}", uuid);
var builder = new StringBuilder();
builder.AppendFormat("\tstatic {0}() {{\n", OUTPUT_CLASS_NAME);
builder.AppendFormat("\t\tif (GetBool(\"{0}\")) {{ return; }}\n", firstTimeKey);
builder.AppendFormat("\t\tInitialize();\n");
builder.AppendFormat("\t\tSetBool(\"{0}\", true);\n", firstTimeKey);
builder.AppendLine("\t\tSave();");
builder.AppendLine("\t}");
builder.AppendLine("");
builder.AppendLine("\tprivate static void Initialize() {");
foreach (var init in initializations) {
builder.AppendLine(string.Format("\t\t{0}", init));
}
builder.AppendLine("\t}");
return builder.ToString();
}

private static string ToKeyMember(string pascalCaseKey, string forcedKey) {

var identifier = ToKey(pascalCaseKey);
var key = forcedKey == null ? identifier : forcedKey;
return string.Format("\tprivate const string {0} = \"{1}\";", identifier, key);
}

private static string ToProperty(string propName, string type, string defaultValue = null) {

var key = ToKey(propName);

switch (type) {
case "bool": return GenerateBoolProperty(propName, key, defaultValue);
case "string": return GenerateStringProperty(propName, key, defaultValue);
case "int": return GenerateIntProperty(propName, key, defaultValue);
case "float": return GenerateFloatProperty(propName, key, defaultValue);
default: throw new System.Exception(string.Format("Unrecognized type: {0}", type));
}
}

private static string GenerateBoolProperty(string propName, string key, string defaultVal) {
var defaultValue = defaultVal == null ? "true" : defaultVal;
return string.Format("\tpublic static bool {0} {{\n" +
"\t\tget {{ return GetBool({1}, {2}); }}\n" +
"\t\tset {{ SetBool({1}, value); }}\n" +
"\t}}", propName, key, defaultValue);
}

private static string GenerateStringProperty(string propName, string key, string defaultVal) {
var defaultValue = defaultVal == null ? "\"\"" : defaultVal;
return string.Format("\tpublic static string {0} {{\n" +
"\t\tget {{ return PlayerPrefs.GetString({1}, {2}); }}\n" +
"\t\tset {{ PlayerPrefs.SetString({1}, value); Save(); }}\n" +
"\t}}", propName, key, defaultValue);
}

private static string GenerateIntProperty(string propName, string key, string defaultVal) {
var defaultValue = defaultVal == null ? "-1" : defaultVal;
return string.Format("\tpublic static int {0} {{\n" +
"\t\tget {{ return PlayerPrefs.GetInt({1}, {2}); }}\n" +
"\t\tset {{ PlayerPrefs.SetInt({1}, value); Save(); }}\n" +
"\t}}", propName, key, defaultValue);
}

private static string GenerateFloatProperty(string propName, string key, string defaultVal) {
var defaultValue = defaultVal == null ? "-1" : defaultVal;
return string.Format("\tpublic static float {0} {{\n" +
"\t\tget {{ return PlayerPrefs.GetFloat({1}, {2}); }}\n" +
"\t\tset {{ PlayerPrefs.SetFloat({1}, value); Save(); }}\n" +
"\t}}", propName, key, defaultValue);
}

private static string ToKey(string pascalCaseProperty) {
return string.Format("{0}_KEY", ToUpperCase(pascalCaseProperty));
}

private static string ToUpperCase(string pascalCase) {

return UPPERCACSE_PATTERN.Replace(pascalCase, "_$0", int.MaxValue, 2).ToUpper();
}
}
11 changes: 11 additions & 0 deletions Assets/Editor/SettingsGen.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Experiments.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Experiments/Encoding Size.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a4a5b4b

Please sign in to comment.