Add console system to print debug output to the PB screen.
This commit is contained in:
44
Mixins/ConfigParser/ConfigParser.cs
Normal file
44
Mixins/ConfigParser/ConfigParser.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Sandbox.ModAPI.Ingame;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IngameScript
|
||||
{
|
||||
public class ConfigParser
|
||||
{
|
||||
private Dictionary<string, string> _config;
|
||||
private IMyTerminalBlock _input;
|
||||
|
||||
public ConfigParser(IMyTerminalBlock input)
|
||||
{
|
||||
_input = input;
|
||||
_config = new Dictionary<string, string>();
|
||||
Parse();
|
||||
}
|
||||
|
||||
// Get a config value, or a default value.
|
||||
// that also does type inference, but the type of `defaultValue` must contain a `Parse()` method.
|
||||
public T GetValue<T>(string key, T defaultValue)
|
||||
{
|
||||
if (!_config.ContainsKey(key))
|
||||
{
|
||||
return defaultValue;
|
||||
|
||||
}
|
||||
return (T)Convert.ChangeType(_config[key], typeof(T));
|
||||
}
|
||||
|
||||
// Only call this method manually if you are monitoring CustomData for changes.
|
||||
public void Parse()
|
||||
{
|
||||
_config.Clear();
|
||||
string[] lines = _input.CustomData.Split('\n');
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] tokens = line.Split('=');
|
||||
if (tokens.Length != 2) continue;
|
||||
_config[tokens[0]] = tokens[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Mixins/ConfigParser/ConfigParser.projitems
Normal file
11
Mixins/ConfigParser/ConfigParser.projitems
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>8a3cdcc5-4b55-4d87-a415-698a0e1ff06f</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)/**/*.cs" Visible=" '$(ShowCommonFiles)' == 'true' " />
|
||||
</ItemGroup>
|
||||
</Project>
|
19
Mixins/ConfigParser/ConfigParser.shproj
Normal file
19
Mixins/ConfigParser/ConfigParser.shproj
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>8a3cdcc5-4b55-4d87-a415-698a0e1ff06f</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props"/>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props"/>
|
||||
<PropertyGroup/>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="ConfigParser.projitems" Label="Shared"/>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets"/>
|
||||
</Project>
|
Reference in New Issue
Block a user