Skip to content

Commit

Permalink
Add Def Template Exporter Module
Browse files Browse the repository at this point in the history
  • Loading branch information
duduluu committed Dec 2, 2017
1 parent ddf6e9d commit 784565c
Show file tree
Hide file tree
Showing 17 changed files with 371 additions and 13 deletions.
4 changes: 2 additions & 2 deletions RimTrans.Builder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.18.2.2")]
[assembly: AssemblyFileVersion("0.18.2.2")]
[assembly: AssemblyVersion("0.18.2.3")]
[assembly: AssemblyFileVersion("0.18.2.3")]
4 changes: 2 additions & 2 deletions RimTrans.Lite/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.18.2.2")]
[assembly: AssemblyFileVersion("0.18.2.2")]
[assembly: AssemblyVersion("0.18.2.3")]
[assembly: AssemblyFileVersion("0.18.2.3")]
6 changes: 5 additions & 1 deletion RimTrans.Lite/Resources/DefaultSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
<s:Double x:Key="AddModWindowWidth">971</s:Double>

<s:Boolean x:Key="ExtractDoNotPromptClean">False</s:Boolean>


<s:Double x:Key="ToolsWindowHeight">600</s:Double>
<s:Double x:Key="ToolsWindowWidth">971</s:Double>
<s:String x:Key="DefTemplateOutputPath">C:\git\rw\RimWorld-Defs-Templates</s:String>

<s:Double x:Key="OptionsWindowHeight">600</s:Double>
<s:Double x:Key="OptionsWindowWidth">971</s:Double>
<s:Boolean x:Key="OptionsDoNotPromptDirNoFound">False</s:Boolean>
Expand Down
8 changes: 8 additions & 0 deletions RimTrans.Lite/RimTrans.Lite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Windows\AddLanguageWindow.xaml.cs">
<DependentUpon>AddLanguageWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\ToolsViewModel.cs" />
<Compile Include="Windows\BackstoryWindow.xaml.cs">
<DependentUpon>BackstoryWindow.xaml</DependentUpon>
</Compile>
Expand All @@ -113,6 +114,9 @@
<Compile Include="Windows\OptionsWindow.xaml.cs">
<DependentUpon>OptionsWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\ToolsWindow.xaml.cs">
<DependentUpon>ToolsWindow.xaml</DependentUpon>
</Compile>
<Page Include="Controls\Dialogs\AwesomeDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -229,6 +233,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\ToolsWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down
24 changes: 24 additions & 0 deletions RimTrans.Lite/Util/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,30 @@ public string BackstoriesTargetFile

#endregion

#region Window Tools

public double ToolsWindowHeight {
get { return (double)GetValue(); }
set { SetValue(value); }
}

public double ToolsWindowWidth {
get { return (double)GetValue(); }
set { SetValue(value); }
}

public string DefTemplateOutputPath {
get { return (string)GetValue(); }
set { SetValue(value); }
}

public bool DefTemplateOpenFolder {
get { return (bool)GetValue(); }
set { SetValue(value); }
}

#endregion

#region Window Options

public double OptionsWindowHeight
Expand Down
10 changes: 10 additions & 0 deletions RimTrans.Lite/Windows/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ private void ExecuteBackstory(object parameter)
window.Show();
}

// Tools
private RelayCommand _commandTools;
public RelayCommand CommandTools {
get { return _commandTools ?? (_commandTools = new RelayCommand(ExecuteTools)); }
}
private void ExecuteTools(object parameter) {
var window = new ToolsWindow();
var dialogResult = window.ShowDialog(View);
}

// Options
private RelayCommand _commandOptions;
public RelayCommand CommandOptions
Expand Down
8 changes: 4 additions & 4 deletions RimTrans.Lite/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@
<StackPanel x:Name="toolbarRight"
Background="{StaticResource Lite.Main.Background}"
Grid.Row="1" Height="64" Width="auto" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5,0" >
<c:AwesomeButton x:Name="backstory" Command="{Binding CommandBackstory}"
Icon="AddressBook" Text="{DynamicResource Common.Backstory}" Style="{StaticResource Style.AwesomeButton.Large}"/>
<!--<c:AwesomeButton x:Name="buttonTools" IsEnabled="False"
Icon="Briefcase" Text="{DynamicResource MainWindow.Button.Tools}" Style="{StaticResource Style.AwesomeButton.Large}"/>-->
<!--<c:AwesomeButton x:Name="backstory" Command="{Binding CommandBackstory}"
Icon="AddressBook" Text="{DynamicResource Common.Backstory}" Style="{StaticResource Style.AwesomeButton.Large}"/>-->
<c:AwesomeButton x:Name="buttonTools" Command="{Binding CommandTools}"
Icon="Briefcase" Text="{DynamicResource MainWindow.Button.Tools}" Style="{StaticResource Style.AwesomeButton.Large}"/>
<c:AwesomeButton x:Name="buttonHelp" Click="buttonHelp_Click"
Icon="Question" Text="{DynamicResource MainWindow.Button.Help}" Style="{StaticResource Style.AwesomeButton.Large}"/>
<c:AwesomeButton x:Name="buttonOptions" Command="{Binding CommandOptions}"
Expand Down
42 changes: 42 additions & 0 deletions RimTrans.Lite/Windows/ToolsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using duduluu.MVVM;
using RimTrans.Lite.Controls;
using RimTrans.Lite.Util;

namespace RimTrans.Lite.Windows
{
public class ToolsViewModel : ViewModelBase
{
public ToolsViewModel()
{

}

public ToolsWindow View { get; set; }

// TemplateExport
private bool CanExecuteExport(object parameter) {
return !string.IsNullOrWhiteSpace(UserSettings.All.DefTemplateOutputPath);
}
private RelayCommand _commandTemplateExport;
public RelayCommand CommandTemplateExport {
get { return _commandTemplateExport ?? (_commandTemplateExport = new RelayCommand(ExecuteTemplateExport, CanExecuteExport)); }
}
private void ExecuteTemplateExport(object parameter) {
string defsPath = Path.Combine(UserSettings.All.RimWorldInstallDir, "Mods", "Core", "Defs");
string outputPath = UserSettings.All.DefTemplateOutputPath;
string arguments = $"\"{defsPath}\" \"{outputPath}\"";
if (UserSettings.All.DefTemplateOpenFolder) {
Process.Start("explorer.exe", $"\"{outputPath}\"");
}
Process.Start("TemplateExporter.exe", arguments);
}
}
}
61 changes: 61 additions & 0 deletions RimTrans.Lite/Windows/ToolsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Window x:Class="RimTrans.Lite.Windows.ToolsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RimTrans.Lite.Windows"
xmlns:u="clr-namespace:RimTrans.Lite.Util"
xmlns:c="clr-namespace:RimTrans.Lite.Controls"
xmlns:co="clr-namespace:RimTrans.Lite.Converters"
mc:Ignorable="d"
x:Name="Tools"
Title="{DynamicResource MainWindow.Button.Tools}"
Height="{Binding Source={x:Static u:UserSettings.All}, Path=ToolsWindowHeight, Mode=TwoWay}"
Width="{Binding Source={x:Static u:UserSettings.All}, Path=ToolsWindowWidth, Mode=TwoWay}"
MinHeight="500" MinWidth="809" ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterOwner"
Background="{StaticResource Lite.Main.Background}"
SnapsToDevicePixels="True">
<Window.DataContext>
<local:ToolsViewModel x:Name="vm"/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<StackPanel Grid.RowSpan="2" Style="{StaticResource Style.Sidebar}">
<c:AwesomeRadioButton x:Name="templateExport"
IsChecked="True"
Icon="FileCodeOutline" Text="Def Template Exporter"
Style="{StaticResource Style.AwesomeRadioButton.Sidebar.Content}"/>
</StackPanel>

<!-- All Panel -->
<Grid Grid.Column="1" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="20">

<!-- TemplateExport -->
<StackPanel Grid.Column="1" Visibility="{Binding IsChecked, ElementName=templateExporter, Converter={StaticResource BooleanToVisibilityConverter}}"
Orientation="Vertical" HorizontalAlignment="Stretch">
<GroupBox Header="Def Template Output Path" Margin="10" Style="{StaticResource Style.GroupBox}">
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
<TextBox Text="{Binding Source={x:Static u:UserSettings.All}, Path=DefTemplateOutputPath}"
Margin="4" Style="{StaticResource Style.TextBox.Label}"/>
<Grid HorizontalAlignment="Stretch">
<CheckBox Content="Open folder after exporting" IsChecked="{Binding Source={x:Static u:UserSettings.All}, Path=DefTemplateOpenFolder}"
Margin="10,0" Style="{StaticResource Style.AwesomeCheckBox.Content}"/>
<Button Command="{Binding CommandTemplateExport}"
HorizontalAlignment="Right"
Content="Export" Margin="5" Style="{StaticResource Sylte.Button.Wide}"/>
</Grid>
</StackPanel>
</GroupBox>
</StackPanel>
<!-- TemplateExport End -->
</Grid>
</Grid>
</Window>
25 changes: 25 additions & 0 deletions RimTrans.Lite/Windows/ToolsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace RimTrans.Lite.Windows {
/// <summary>
/// Tools.xaml 的交互逻辑
/// </summary>
public partial class ToolsWindow : Window {
public ToolsWindow() {
InitializeComponent();
vm.View = this;
}
}
}
6 changes: 6 additions & 0 deletions RimTrans.TemplateExporter/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
65 changes: 65 additions & 0 deletions RimTrans.TemplateExporter/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using RimTrans.Builder;
using RimTrans.Builder.Crawler;

namespace RimTrans.TemplateExporter {
class Program {
static void Main(string[] args) {

#region Application Info

Assembly asm = Assembly.GetExecutingAssembly();
string title = asm.GetCustomAttribute<AssemblyTitleAttribute>().Title;
Console.Title = title;
Console.OutputEncoding = Encoding.Unicode;

#endregion

if (args.Length != 2) {
Log.Error();
Log.WriteLine("Need 2 arguments: defsPath and outputPath.");
} else if (string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1])) {
Log.Error();
Log.WriteLine("Need 2 arguments: defsPath and outputPath.");
} else {
Gen_DefsTemplate(args[0], args[1]);
}
Log.WriteLine();
Log.Write("Press any key to exit...");
Console.ReadKey();
return;
}

public static void Gen_DefsTemplate(string defsPath, string outputPath) {
if (!Directory.Exists(defsPath)) {
Log.Error();
Log.WriteLine($"Directory no found: {defsPath}");
return;
}

string sourceCodePath = Path.Combine(Directory.GetCurrentDirectory(), "Assembly-CSharp");
if (Directory.Exists(sourceCodePath)) {
Log.Info();
Log.WriteLine();
} else {
sourceCodePath = null;
}

DefinitionData coreDefinitionData = DefinitionData.Load(defsPath);

Capture capture = Capture.Parse(coreDefinitionData);
capture.ProcessFieldNames(coreDefinitionData);
coreDefinitionData.Save(Path.Combine(outputPath, "CoreDefsProcessed"));

Capture templates = Capture.Parse(coreDefinitionData, sourceCodePath, true);
templates.Save(Path.Combine(outputPath, "Templates"));
}
}
}
36 changes: 36 additions & 0 deletions RimTrans.TemplateExporter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("RimTrans.TemplateExporter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RimTrans.TemplateExporter")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("4a841417-f517-4b5b-af88-f29bc0a0095f")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.18.2.3")]
[assembly: AssemblyFileVersion("0.18.2.3")]
Binary file not shown.
Loading

0 comments on commit 784565c

Please sign in to comment.