-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: Add table script utility similar to vptscript in vpx-js
- Loading branch information
Showing
6 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.IO; | ||
using VisualPinball.Engine.VPT.Table; | ||
|
||
namespace VisualPinball.TableScript | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
// validate inputs | ||
try { | ||
if (args.Length < 1) { | ||
throw new ArgumentException("USAGE: VisualPinball.TableScript <input file or folder> [<output folder>]"); | ||
} | ||
|
||
// input file(s) | ||
if (!FileOrDirectoryExists(args[0])) { | ||
throw new ArgumentException($"Non-existent input path: \"{args[0]}\"."); | ||
} | ||
var inputAttr = File.GetAttributes(args[0]); | ||
var inputFiles = (inputAttr & FileAttributes.Directory) == FileAttributes.Directory | ||
? Directory.GetFiles(args[0], "*.vpx") | ||
: new[] {args[0]}; | ||
if (inputFiles.Length == 0) { | ||
throw new ArgumentException($"No .vpx files found at \"{args[0]}\""); | ||
} | ||
|
||
// output folder | ||
string outputDir = null; | ||
|
||
if (args.Length > 1) { | ||
outputDir = args[1]; | ||
if (!Directory.Exists(outputDir)) { | ||
throw new ArgumentException($"Invalid output folder \"{outputDir}\"."); | ||
} | ||
} | ||
|
||
foreach (var inputFile in inputFiles) { | ||
Console.WriteLine($"Processing \"{inputFile}\"..."); | ||
|
||
var inputTable = TableLoader.Load(inputFile); | ||
|
||
var code = inputTable.Data.Code; | ||
|
||
if (Environment.NewLine == "\n") { | ||
code = code.Replace("\r\r\n", "\n"); | ||
code = code.Replace("\r\n", "\n"); | ||
code = code.Replace("\r", "\n"); | ||
} | ||
|
||
if (outputDir != null) { | ||
var outputFilePath = Path.Join(outputDir, Path.GetFileNameWithoutExtension(inputFile) + ".vbs"); | ||
|
||
File.WriteAllText(outputFilePath, code); | ||
} | ||
else { | ||
Console.WriteLine(code); | ||
} | ||
} | ||
|
||
} catch (ArgumentException e) { | ||
Console.WriteLine(e.Message); | ||
|
||
} catch (Exception e) { | ||
Console.WriteLine(e); | ||
} | ||
} | ||
|
||
private static bool FileOrDirectoryExists(string name) | ||
{ | ||
return Directory.Exists(name) || File.Exists(name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Table Script | ||
|
||
This is a command line tool that simply: | ||
|
||
- Reads all `.vpx` files in a folder (or a single file) | ||
- Optionally takes in an output folder | ||
|
||
It then: | ||
|
||
- Extracts all input table scripts | ||
- Converts CR/LF to NL on Unix systems | ||
- Saves the table scripts to the output folder if specified, otherwise outputs to the console. | ||
|
||
## Usage | ||
|
||
Usage is pretty simple: | ||
|
||
```bash | ||
VisualPinball.TableScript <.vpx or input folder> [<output folder>] | ||
``` | ||
|
||
## Compilation | ||
|
||
To get a single binary on Windows: | ||
|
||
```bash | ||
dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true | ||
``` | ||
|
||
To get a single binary on MacOS: | ||
|
||
```bash | ||
dotnet publish -r osx-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true | ||
``` | ||
|
||
|
||
To get a single binary on Linux: | ||
|
||
```bash | ||
dotnet publish -r linux-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true | ||
``` |
17 changes: 17 additions & 0 deletions
17
VisualPinball.TableScript/VisualPinball.TableScript.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<Company>Visual Pinball Engine</Company> | ||
<Product>Table Script</Product> | ||
<AssemblyVersion>0.0.3.0</AssemblyVersion> | ||
<FileVersion>0.0.3.0-SNAPSHOT</FileVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="VisualPinball.Engine" Version="0.0.1-preview.46" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters