Skip to content

Commit

Permalink
Codices
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverfeelin committed Aug 11, 2017
1 parent 3f0bb33 commit e6c471e
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 20 deletions.
109 changes: 109 additions & 0 deletions SpawnableItemFetcher/SpawnableItemFetcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ static ResultType PromptResultType()
/// <param name="file">File to scan. Expected to be a JSON formatted item file.</param>
static void AddItem(FileInfo file)
{
if (file.Extension == ".codex")
{
AddCodex(file);
return;
}

// Read file
string content = File.ReadAllText(file.FullName);

Expand Down Expand Up @@ -268,7 +274,71 @@ static void AddItem(FileInfo file)
result.Add(newItem);
break;
}
}

static void AddCodex(FileInfo file)
{
// Read file
string content = File.ReadAllText(file.FullName);

// Parse file
JObject item = null;
try
{
item = JObject.Parse(content);
}
catch
{
Console.WriteLine("Skipped '" + file.FullName + "', as it could not be parsed as a valid JSON file.");
return;
}

JObject newItem = new JObject();

newItem["path"] = AssetPath(file.FullName, basePath);
newItem["fileName"] = file.Name;

// Set item name
string name = GetCodexName(item);
newItem["name"] = name;

if (string.IsNullOrEmpty(name))
return;

// Set item description. Use item name if no description is set.
string shortDescription = GetCodexTitle(item);
if (string.IsNullOrEmpty(shortDescription))
shortDescription = name;
newItem["shortdescription"] = shortDescription;

// Set category
newItem["category"] = "codex";

// Set icon
newItem["icon"] = GetIcon(item, true);

// Set rarity.
string rarity = GetCodexRarity(item);
if (rarity != null)
newItem["rarity"] = rarity;

// Set race
string race = GetSpecies(item);
if (race != null)
newItem["race"] = race;

// Add the item.
switch (resultType)
{
case ResultType.Patch:
JObject patch = JObject.Parse("{'op':'add','path':'/-','value':{}}");
patch["value"] = newItem;
result.Add(patch);
break;
case ResultType.Normal:
result.Add(newItem);
break;
}
}

static string GetItemName(JObject item)
Expand All @@ -284,6 +354,17 @@ static string GetItemName(JObject item)
return name?.Value<string>();
}

static string GetCodexName(JObject item)
{
JToken name = item["id"];
if (name != null && name.Type == JTokenType.String)
{
return name.Value<string>() + "-codex";
}

return null;
}

static string GetItemShortDescription(JObject item)
{
JToken tkn = item["shortdescription"];
Expand All @@ -294,6 +375,16 @@ static string GetItemShortDescription(JObject item)
return tkn?.Value<string>();
}

static string GetCodexTitle(JObject item)
{
JToken tkn = item["title"];

if (tkn != null && tkn.Type != JTokenType.String)
return null;

return tkn?.Value<string>();
}

/// <summary>
/// Returns the category of the item.
/// Uses the item extension if no category could be found, and has a couple of overrides.
Expand Down Expand Up @@ -424,6 +515,15 @@ static string GetRarity(JObject item, string defaultRarity = "common")
return tkn.Value<string>().ToLowerInvariant();
}

static string GetCodexRarity(JObject item, string defaultRarity = "common")
{
JToken tkn = item.SelectToken("itemConfig.rarity");
if (tkn == null || tkn.Type != JTokenType.String)
return defaultRarity;

return tkn.Value<string>().ToLowerInvariant();
}

static string GetRace(JObject item)
{
JToken tkn = item["race"];
Expand All @@ -433,6 +533,15 @@ static string GetRace(JObject item)
return tkn.Value<string>().ToLowerInvariant();
}

static string GetSpecies(JObject item)
{
JToken tkn = item["species"];
if (tkn == null || tkn.Type != JTokenType.String)
return null;

return tkn.Value<string>().ToLowerInvariant();
}

/// <summary>
/// Scans the directory and all subdirectories, running the callback for each found file.
/// </summary>
Expand Down
Binary file modified SpawnableItemFetcher/build/SpawnableItemFetcher.exe
Binary file not shown.
Binary file added interface/sip/categories/codices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added interface/sip/categories/codicesselected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 27 additions & 18 deletions interface/sip/sip.config
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,24 @@
"position": [75, -264],
"data": ["eppaugment", "petcollar"]
},
{
"baseImage": "/interface/sip/categories/codices.png",
"hoverImage": "/interface/sip/categories/codices.png?brightness=30",
"baseImageChecked": "/interface/sip/categories/codicesselected.png",
"hoverImageChecked": "/interface/sip/categories/codicesselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [112, -264],
"data": "codex"
},
{
"baseImage": "/interface/sip/categories/other.png",
"hoverImage": "/interface/sip/categories/other.png?brightness=30",
"baseImageChecked": "/interface/sip/categories/otherselected.png",
"hoverImageChecked": "/interface/sip/categories/otherselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [112, -264],
"data": [
"miscellaneous", "codex", "quest", "junk", "currency", "trophy", "tradingcard"
"position": [1, -289],
"data": [
"miscellaneous", "quest", "junk", "currency", "trophy", "tradingcard"
]
},
{
Expand All @@ -508,7 +517,7 @@
"baseImageChecked": "/interface/sip/categories/matitemsselected.png",
"hoverImageChecked": "/interface/sip/categories/matitemsselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [1, -297],
"position": [1, -322],
"data": [
"blocks", "block", "materials", "liqitem", "supports", "railpoint"
]
Expand All @@ -519,7 +528,7 @@
"baseImageChecked": "/interface/sip/categories/decorativesselected.png",
"hoverImageChecked": "/interface/sip/categories/decorativesselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [38, -297],
"position": [38, -322],
"data": [
"decorative", "actionfigure", "artifact", "breakable", "bug"
]
Expand All @@ -530,7 +539,7 @@
"baseImageChecked": "/interface/sip/categories/craftingselected.png",
"hoverImageChecked": "/interface/sip/categories/craftingselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [75, -297],
"position": [75, -322],
"data": "crafting"
},
{
Expand All @@ -539,7 +548,7 @@
"baseImageChecked": "/interface/sip/categories/spawnerselected.png",
"hoverImageChecked": "/interface/sip/categories/spawnerselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [112, -297],
"position": [112, -322],
"data": "spawner"
},
{
Expand All @@ -548,7 +557,7 @@
"baseImageChecked": "/interface/sip/categories/doorsselected.png",
"hoverImageChecked": "/interface/sip/categories/doorsselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [1, -322],
"position": [1, -347],
"data": "door"
},
{
Expand All @@ -557,7 +566,7 @@
"baseImageChecked": "/interface/sip/categories/furnitureselected.png",
"hoverImageChecked": "/interface/sip/categories/furnitureselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [38, -322],
"position": [38, -347],
"data": "furniture"
},
{
Expand All @@ -566,7 +575,7 @@
"baseImageChecked": "/interface/sip/categories/chestsselected.png",
"hoverImageChecked": "/interface/sip/categories/chestsselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [75, -322],
"position": [75, -347],
"data": "storage"
},
{
Expand All @@ -575,7 +584,7 @@
"baseImageChecked": "/interface/sip/categories/lightsselected.png",
"hoverImageChecked": "/interface/sip/categories/lightsselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [112, -322],
"position": [112, -347],
"data": "light"
},
{
Expand All @@ -584,7 +593,7 @@
"baseImageChecked": "/interface/sip/categories/trapsselected.png",
"hoverImageChecked": "/interface/sip/categories/trapsselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [1, -347],
"position": [1, -372],
"data": "trap"
},
{
Expand All @@ -593,7 +602,7 @@
"baseImageChecked": "/interface/sip/categories/wiredselected.png",
"hoverImageChecked": "/interface/sip/categories/wiredselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [38, -347],
"position": [38, -372],
"data": "wire"
},
{
Expand All @@ -602,7 +611,7 @@
"baseImageChecked": "/interface/sip/categories/produceselected.png",
"hoverImageChecked": "/interface/sip/categories/produceselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [75, -347],
"position": [75, -372],
"data": ["produce", "sapling", "seed"]
},
{
Expand All @@ -620,7 +629,7 @@
"baseImageChecked": "/interface/sip/categories/platformsselected.png",
"hoverImageChecked": "/interface/sip/categories/platformsselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [1, -372],
"position": [1, -397],
"data": "platform"
},
{
Expand All @@ -629,7 +638,7 @@
"baseImageChecked": "/interface/sip/categories/liquidsselected.png",
"hoverImageChecked": "/interface/sip/categories/liquidsselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [38, -372],
"position": [38, -397],
"data": "liquid"
},
{
Expand All @@ -638,7 +647,7 @@
"baseImageChecked": "/interface/sip/categories/terraformerselected.png",
"hoverImageChecked": "/interface/sip/categories/terraformerselected.png?brightness=30",
"pressedOffset": [0, -1],
"position": [75, -372],
"position": [75, -397],
"data": "terraformer"
}
]
Expand Down Expand Up @@ -709,7 +718,7 @@
},
"sipLabelCatObjects": {
"type": "label",
"position": [1, -265],
"position": [1, -290],
"hAnchor": "left",
"vAnchor": "top",
"zlevel": 22,
Expand Down
2 changes: 1 addition & 1 deletion quickbar/spawnableItemPackLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local categoryButtons = categoryGroup.buttons

local modCategories = root.assetJson("/sipMods/categories.config")

local x, y, i = 1, -372, 0
local x, y, i = 1, -397, 0
local buttonOffset = {37, -25}
local labelOffset = {0, -8}

Expand Down
2 changes: 1 addition & 1 deletion sipItemDump.json

Large diffs are not rendered by default.

0 comments on commit e6c471e

Please sign in to comment.