260 lines
11 KiB
C#
260 lines
11 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MxFilterGen2.Compiler
|
|
{
|
|
public class Block
|
|
{
|
|
public string Type { get; set; }
|
|
public bool Show { get; set; }
|
|
public List<object> Class { get; set; }
|
|
public List<object> BaseType { get; set; }
|
|
public List<string> SetTextColor { get; set; }
|
|
public List<string> SetBackgroundColor { get; set; }
|
|
public List<string> SetBorderColor { get; set; }
|
|
public string SetFontSize { get; set; }
|
|
public List<Condition> Conditions { get; set; }
|
|
public List<Action> Actions { get; set; }
|
|
}
|
|
|
|
public class Condition
|
|
{
|
|
public string name { get; set; }
|
|
public string op { get; set; }
|
|
public string value { get; set; }
|
|
}
|
|
|
|
public class Action
|
|
{
|
|
public string name { get; set; }
|
|
public string va { get; set; }
|
|
public string vb { get; set; }
|
|
public string vc { get; set; }
|
|
public string vd { get; set; }
|
|
}
|
|
|
|
public class RootBlocks
|
|
{
|
|
public List<Block> blocks { get; set; }
|
|
}
|
|
internal class section
|
|
{
|
|
public static string outpath = "";
|
|
private static string iC;
|
|
private static string iB;
|
|
public static void Compile(string section, string filter)
|
|
{
|
|
if (File.Exists(outpath)) { File.Delete($"out/{section}.filter"); }
|
|
|
|
//DoSplash(filter, section);
|
|
|
|
string filson = $"filson/{section}.json";
|
|
|
|
//Message.CMW($"[{filter}] Block(s): {JsonConvert.DeserializeObject<RootBlocks>(File.ReadAllText(filson, Encoding.UTF8)).blocks.Count}", true, 2);
|
|
|
|
foreach (Block bl in JsonConvert.DeserializeObject<RootBlocks>(File.ReadAllText(filson, Encoding.UTF8)).blocks)
|
|
{
|
|
string blocktype = bl.Type;
|
|
outpath = $"out/{filter}/{section}.filter";
|
|
DoCompile(bl, blocktype, filter);
|
|
}
|
|
}
|
|
|
|
public static void DoSplash(string filter, string section)
|
|
{
|
|
string outp = $"out/{filter}/{section}.filter";
|
|
////////// Splash //////////
|
|
File.AppendAllText(outp, $"#### Filson - PoE2 Item Filter JSON Parsing - MxFilterGen2 v{Program.version}{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### Filson and MxFilterGen2 are developped by mikx.{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### MxGit: https://mxgit.ovh/mikx/PoE-MxFilterGen2{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### MxPoE: https://mxpoe.ovh/{Environment.NewLine}");
|
|
File.AppendAllText(outp, $"#### Contact: mikx@mxpoe.ovh / http://discord.mxg.ovh{Environment.NewLine}");
|
|
}
|
|
|
|
public static void DoCompile(Block bl, string bltype, string type)
|
|
{
|
|
////////// Skip a line //////////
|
|
File.AppendAllText(outpath, Environment.NewLine);
|
|
////////// Show or Hide //////////
|
|
string bshow = "";
|
|
if (bl.Show) { bshow = "Show"; } else { bshow = "Hide"; };
|
|
if (bltype == "Normal" && type == "Strict") { bshow = "Hide"; }
|
|
File.AppendAllText(outpath, bshow + Environment.NewLine);
|
|
////////// Class //////////
|
|
if (bl.Class != null)
|
|
{
|
|
foreach (var c in bl.Class) { iC += string.Format(@" ""{0}""", c); }
|
|
if (iC != "")
|
|
{
|
|
File.AppendAllText(outpath, $" Class {iC} {Environment.NewLine}");
|
|
}
|
|
}
|
|
////////// Base //////////
|
|
if (bl.BaseType != null)
|
|
{
|
|
foreach (var b in bl.BaseType) { iB += string.Format(@" ""{0}""", b); }
|
|
if (iB != "")
|
|
{
|
|
File.AppendAllText(outpath, $" BaseType {iB} {Environment.NewLine}");
|
|
}
|
|
}
|
|
////////// SetTextColor //////////
|
|
if (bl.SetTextColor[0] != null)
|
|
{
|
|
File.AppendAllText(outpath, $" SetTextColor {bl.SetTextColor[0]} {Environment.NewLine}");
|
|
}
|
|
////////// SetBackgroundColor //////////
|
|
if (bl.SetBackgroundColor[0] != null)
|
|
{
|
|
File.AppendAllText(outpath, $" SetBackgroundColor {bl.SetBackgroundColor[0]} {Environment.NewLine}");
|
|
}
|
|
////////// SetBorderColor //////////
|
|
if (bl.SetBorderColor[0] != null)
|
|
{
|
|
File.AppendAllText(outpath, $" SetBorderColor {bl.SetBorderColor[0]} {Environment.NewLine}");
|
|
}
|
|
////////// SetFontSize //////////
|
|
if (bl.SetFontSize != null)
|
|
{
|
|
File.AppendAllText(outpath, " SetFontSize " + bl.SetFontSize + Environment.NewLine);
|
|
}
|
|
////////// Conditions //////////
|
|
foreach (var con in bl.Conditions)
|
|
{
|
|
string cn = con.name;
|
|
string co = con.op;
|
|
var cv = con.value;
|
|
switch (con.name)
|
|
{
|
|
case "AreaLevel":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "ItemLevel":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "DropLevel":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "Quality":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "Rarity":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "LinkedSockets":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "SocketGroup":
|
|
File.AppendAllText(outpath, $" {cn} {co} \"{cv}\" {Environment.NewLine}");
|
|
break;
|
|
case "Sockets":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "Height":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "Width":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "HasExplicitMod":
|
|
File.AppendAllText(outpath, $" {cn} \"{cv}\" {Environment.NewLine}");
|
|
break;
|
|
case "AnyEnchantment":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "StackSize":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "GemLevel":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "GemQualityType":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "AlternateQuality":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "Identified":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "Corrupted":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "Mirrored":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "ElderItem":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "ShaperItem":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "HasInfluence":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "FracturedItem":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "SynthesisedItem":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "BlightedMap":
|
|
File.AppendAllText(outpath, $" {cn} {cv} {Environment.NewLine}");
|
|
break;
|
|
case "MapTier":
|
|
File.AppendAllText(outpath, $" {cn} {co} {cv} {Environment.NewLine}");
|
|
break;
|
|
|
|
}
|
|
}
|
|
////////// Actions //////////
|
|
if (bltype == "Normal" && type == "Strict")
|
|
{
|
|
// No Action
|
|
}
|
|
else
|
|
{
|
|
foreach (var ac in bl.Actions)
|
|
{
|
|
string an;
|
|
string ava;
|
|
string avb;
|
|
string avc;
|
|
string avd;
|
|
an = ac.name;
|
|
ava = "";
|
|
avb = "";
|
|
avc = "";
|
|
avd = "";
|
|
if (ava != null) { ava = ac.va; }
|
|
if (avb != null) { avb = ac.vb; }
|
|
if (avc != null) { avc = ac.vc; }
|
|
if (avd != null) { avd = ac.vd; }
|
|
switch (ac.name)
|
|
{
|
|
case "PlayAlertSound":
|
|
File.AppendAllText(outpath, $" {an} {ava} {avb} {Environment.NewLine}");
|
|
break;
|
|
case "CustomAlertSound":
|
|
File.AppendAllText(outpath, $" {an} \"{ava}\" {Environment.NewLine}");
|
|
break;
|
|
case "MinimapIcon":
|
|
File.AppendAllText(outpath, $" {an} {ava} {avb} {avc} {Environment.NewLine}");
|
|
break;
|
|
case "PlayEffect":
|
|
File.AppendAllText(outpath, $" {an} {ava} {avb} {Environment.NewLine}");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
iB = "";
|
|
iC = "";
|
|
}
|
|
}
|
|
}
|