Commit a5d2ce1b authored by Adam Leyshon's avatar Adam Leyshon
Browse files

General code tidy up.

parent 34bc0d9c
using System;
#region License
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, Building_PrimeUplink.cs, Created 2018-08-17
#endregion
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
namespace Glitterworld_Prime
{
class Building_PrimeUplink : Building
internal class Building_PrimeUplink : Building
{
#region Methods
internal static bool HasUplink(Map map)
{
var poweredList = new List<Thing>();
......@@ -16,12 +24,12 @@ namespace Glitterworld_Prime
foreach (var uplinkThing in alllist)
{
var trader = uplinkThing.TryGetComp<CompPowerTrader>();
if (trader != null && trader.PowerOn)
{
poweredList.Add(uplinkThing);
}
if (trader != null && trader.PowerOn) poweredList.Add(uplinkThing);
}
return poweredList.Count > 0;
}
#endregion
}
}
}
\ No newline at end of file
......@@ -3,13 +3,14 @@
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, Building_TradeWithPrime.cs, Created 2017-11-18
// Glitterworld Prime, Building_TradeWithPrime.cs, Created 2018-07-22
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using Glitterworld_Prime.Tools;
using RimWorld;
using Verse;
using Verse.AI;
......@@ -55,7 +56,7 @@ namespace Glitterworld_Prime
};
return floatMenuOptions;
}
floatMenuOptions = new List<FloatMenuOption>();
var tradeship = mapComponent.GetTradeShip();
var communicable = (ICommunicable) tradeship; // Cast trader as ICommunicable;
......@@ -84,11 +85,12 @@ namespace Glitterworld_Prime
#if DEBUG
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption("Dump Thing data", Tools.DumpThingData.DumpData, MenuOptionPriority.InitiateSocial, null, null, 0f,
new FloatMenuOption("Dump Thing data", DumpThingData.DumpData, MenuOptionPriority.InitiateSocial, null,
null, 0f,
null, null), myPawn, this, "ReservedBy"));
#endif
floatMenuOptions.Add(FloatMenuUtility.DecoratePrioritizedTask(
new FloatMenuOption(tradeship.TraderName, action, MenuOptionPriority.InitiateSocial, null, null, 0f,
null, null), myPawn, this, "ReservedBy"));
......@@ -104,4 +106,4 @@ namespace Glitterworld_Prime
#endregion
}
}
}
\ No newline at end of file
......@@ -28,9 +28,9 @@ namespace Glitterworld_Prime
private readonly ITrader _trader;
private int? _cacheSilver;
private DownloadStatus _isDownloadComplete = DownloadStatus.Incomplete;
private int? _reason;
private bool _resubscribePromptShown;
private GlitterWorldSubscriptionMetadata _subscriptionMeta;
private int? _reason;
#endregion
......@@ -127,13 +127,9 @@ namespace Glitterworld_Prime
case DownloadStatus.Failed:
string message;
if (_reason != null)
{
message = _reason == 403 ? "GWPBanned".Translate() : "GWPUnavailable".Translate();
}
else
{
message = "GWPUnavailable".Translate();
}
Messages.Message(message, MessageTypeDefOf.NegativeEvent);
Close();
......@@ -186,7 +182,7 @@ namespace Glitterworld_Prime
else
{
#if DEBUG
LogWriter.WriteMessage($"Not creating new ID");
LogWriter.WriteMessage("Not creating new ID");
#endif
}
......@@ -217,7 +213,8 @@ namespace Glitterworld_Prime
private Dialog_MessageBox AskRenew(Action confirm, Action cancel)
{
var text1 = $"{"GWPDialogSubscribe1".Translate()} {_subscriptionMeta.SubscriptionCost} {"GWPCurrency".Translate()} {"GWPDialogSubscribe2".Translate()} {"GWPSubscriptionDuration".Translate()}";
var text1 =
$"{"GWPDialogSubscribe1".Translate()} {_subscriptionMeta.SubscriptionCost} {"GWPCurrency".Translate()} {"GWPDialogSubscribe2".Translate()} {"GWPSubscriptionDuration".Translate()}";
var text2 = "Confirm".Translate();
var text3 = "GoBack".Translate();
var text4 = "GWPDialogSubscribeTitle".Translate();
......
......@@ -163,46 +163,46 @@ namespace Glitterworld_Prime
if (Widgets.ButtonText(rect9, "AcceptButton".Translate(), true, false, true))
{
Action action = () =>
{
Log.Message("GWP Starting order build", true);
bool flag;
var tracker = Utilities.GetMapComponent(TradeSession.playerNegotiator.Map).OrderTracker;
if (!TradeSession.deal.TryExecute(out flag))
{
Log.Message("Error at TradeSession.deal.TryExecute() or Colony couldn't afford it", true);
return;
}
if (flag)
{
var orderSuccess = tracker.TryPlaceOrder((TraderPrime)TradeSession.trader);
// Were we able to place the order?
if (orderSuccess)
{
// Yes, Plav a sound and record the trade deal for the pawn.
SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(null);
var pawn = TradeSession.trader as Pawn;
if (pawn != null)
TaleRecorder.RecordTale(TaleDefOf.TradedWith, TradeSession.playerNegotiator, pawn);
}
// If not then the refund was already issued and the error displayed.
// Close the dialog.
Close(false);
}
else
{
LogWriter.WriteErrorMessage(
"Error processing order, RimWorld couldn't complete the trade.");
}
Event.current.Use();
Close();
};
{
Log.Message("GWP Starting order build", true);
bool flag;
var tracker = Utilities.GetMapComponent(TradeSession.playerNegotiator.Map).OrderTracker;
if (!TradeSession.deal.TryExecute(out flag))
{
Log.Message("Error at TradeSession.deal.TryExecute() or Colony couldn't afford it", true);
return;
}
if (flag)
{
var orderSuccess = tracker.TryPlaceOrder((TraderPrime) TradeSession.trader);
// Were we able to place the order?
if (orderSuccess)
{
// Yes, Plav a sound and record the trade deal for the pawn.
SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(null);
var pawn = TradeSession.trader as Pawn;
if (pawn != null)
TaleRecorder.RecordTale(TaleDefOf.TradedWith, TradeSession.playerNegotiator, pawn);
}
// If not then the refund was already issued and the error displayed.
// Close the dialog.
Close(false);
}
else
{
LogWriter.WriteErrorMessage(
"Error processing order, RimWorld couldn't complete the trade.");
}
Event.current.Use();
Close();
};
if (TradeSession.deal.DoesTraderHaveEnoughSilver())
{
var amt = TradeSession.deal.SilverTradeable.CountToTransferToSource;
......@@ -406,7 +406,8 @@ namespace Glitterworld_Prime
if (def.LabelCap.NullOrEmpty())
{
LogWriter.WriteMessage($"ThingCategoryDef {def.defName} has no label!, Not able to filter by this, skipping. Please report to Mod Author.");
LogWriter.WriteMessage(
$"ThingCategoryDef {def.defName} has no label!, Not able to filter by this, skipping. Please report to Mod Author.");
continue;
}
......
......@@ -25,12 +25,14 @@ namespace Glitterworld_Prime
private readonly ITrader _trader;
private DownloadStatus _isDownloadComplete;
private bool _shouldClose;
private GlitterWorldSubscriptionMetadata _subscriptionMetadata;
private readonly GlitterWorldSubscriptionMetadata _subscriptionMetadata;
#endregion
#region ctor
internal DialogPrimeUpdateSubscription(Pawn playerNegotiator, ITrader traderPrime, GlitterWorldSubscriptionMetadata subData)
internal DialogPrimeUpdateSubscription(Pawn playerNegotiator, ITrader traderPrime,
GlitterWorldSubscriptionMetadata subData)
{
forcePause = true;
absorbInputAroundWindow = true;
......
......@@ -36,7 +36,7 @@ namespace Glitterworld_Prime
internal static string MarketUrl { get; set; }
#endregion
#endregion
#region Methods
......@@ -170,7 +170,8 @@ namespace Glitterworld_Prime
var client = CreateRestClient();
var request = new RestRequest($"/v4/{MarketUrl}/prime_subscription/check/{Utilities.GetMapComponent(map).ColonyId}",
var request = new RestRequest(
$"/v4/{MarketUrl}/prime_subscription/check/{Utilities.GetMapComponent(map).ColonyId}",
Method.GET);
var response = ExecuteRequestExpectData<GlitterWorldSubscriptionMetadata>(client, request);
......@@ -201,7 +202,7 @@ namespace Glitterworld_Prime
var compressed = SerializeAndCompress(request.JsonSerializer, orderRequest);
request.AddFileBytes("order", compressed, "order");
// Make request.
var response = ExecuteRequestNoDataExpected(client, request);
......@@ -299,7 +300,8 @@ namespace Glitterworld_Prime
var client = CreateRestClient();
// Send colony metadata.
var request = new RestRequest($"/v4/{MarketUrl}/prime_subscription/subscribe/" + Utilities.GetMapComponent(map).ColonyId,
var request = new RestRequest(
$"/v4/{MarketUrl}/prime_subscription/subscribe/" + Utilities.GetMapComponent(map).ColonyId,
Method.PUT);
request.AddJsonBody(gsm);
......@@ -372,7 +374,8 @@ namespace Glitterworld_Prime
}
else
{
var request = new RestRequest($"/v4/{MarketUrl}/colonies/" + Utilities.GetMapComponent(map).ColonyId, Method.PUT);
var request = new RestRequest($"/v4/{MarketUrl}/colonies/" + Utilities.GetMapComponent(map).ColonyId,
Method.PUT);
request.AddJsonBody(cmd);
response = ExecuteRequestExpectData<GlitterWorldIdResponse>(client, request);
......@@ -448,7 +451,8 @@ namespace Glitterworld_Prime
LogWriter.WriteMessage("Sending Supported Things Data");
var client = CreateRestClient();
var request = new RestRequest($"/v4/{MarketUrl}/colonies/{mapComponent.ColonyId}/thing_metadata", Method.PUT);
var request = new RestRequest($"/v4/{MarketUrl}/colonies/{mapComponent.ColonyId}/thing_metadata",
Method.PUT);
// Compress the list of things to request and send it as a file.
var compressed = SerializeAndCompress(request.JsonSerializer, mapComponent.GlitterWorldSupportedThingList);
......@@ -498,4 +502,4 @@ namespace Glitterworld_Prime
#endregion
}
}
}
\ No newline at end of file
......@@ -87,7 +87,7 @@ namespace Glitterworld_Prime.ApiStructs
#region Properties
public string Hash { get; set; }
public string ApiCompatible { get;set; }
public string ApiCompatible { get; set; }
#endregion
}
......@@ -102,7 +102,7 @@ namespace Glitterworld_Prime.ApiStructs
}
public GlitterWorldColonyMetadata(string factionName, string planet, string baseName, string ownerType,
string ownerId, int currentTick , bool hasSpawned)
string ownerId, int currentTick, bool hasSpawned)
{
FactionName = factionName;
Planet = planet;
......@@ -130,6 +130,7 @@ namespace Glitterworld_Prime.ApiStructs
public bool HasSpawned { get; set; }
public int LastGameTick { get; set; }
#endregion
}
......@@ -245,8 +246,8 @@ namespace Glitterworld_Prime.ApiStructs
public GlitterWorldSupportedThingList(string locale, IEnumerable<GlitterWorldRequestItem> supportedThings)
{
this.Locale = locale;
this.Things = new List<GlitterWorldRequestItem>(supportedThings);
Locale = locale;
Things = new List<GlitterWorldRequestItem>(supportedThings);
}
#endregion
......@@ -256,6 +257,7 @@ namespace Glitterworld_Prime.ApiStructs
public string Locale { get; set; }
public List<GlitterWorldRequestItem> Things { get; set; }
#endregion
}
......@@ -310,9 +312,7 @@ namespace Glitterworld_Prime.ApiStructs
#region Properties
public List<string> ModList { get; set; }
#endregion
}
}
......@@ -30,4 +30,4 @@ namespace Glitterworld_Prime
#endregion
}
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ namespace Glitterworld_Prime
#region Properties
private Map MapOrderWasPlaced { get; set; }
private Map MapOrderWasPlaced { get; }
internal bool IsDelivered { get; private set; }
......@@ -89,4 +89,4 @@ namespace Glitterworld_Prime
#endregion
}
}
}
\ No newline at end of file
......@@ -60,7 +60,6 @@ namespace Glitterworld_Prime
public float SellPriceOverride { get; set; }
#endregion
//public GlitterWorldItem(string name, float currentBuyPrice, float baseMarketValue, int quantity,
......@@ -77,7 +76,11 @@ namespace Glitterworld_Prime
public class GlitterWorldItemDumpData : GlitterWorldItem
{
#region Properties
public string LocalizedName { get; set; }
public string LanguageCode { get; set; }
#endregion
}
}
}
\ No newline at end of file
......@@ -102,4 +102,4 @@ namespace Glitterworld_Prime
#endregion
}
}
}
\ No newline at end of file
......@@ -290,7 +290,7 @@ namespace Glitterworld_Prime
else
{
#if DEBUG
LogWriter.WriteErrorMessage($"Callback tried to update an order we don't have.");
LogWriter.WriteErrorMessage("Callback tried to update an order we don't have.");
#endif
}
}
......@@ -303,11 +303,11 @@ namespace Glitterworld_Prime
else
{
#if DEBUG
LogWriter.WriteErrorMessage($"Got a callback we were not expecting!");
LogWriter.WriteErrorMessage("Got a callback we were not expecting!");
#endif
}
}
#endregion
}
}
}
\ No newline at end of file
......@@ -9,13 +9,8 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Security.Policy;
using Glitterworld_Prime.ApiStructs;
using Harmony;
using RimWorld;
using Verse;
......@@ -27,8 +22,9 @@ namespace Glitterworld_Prime
private string _colonyId = "";
private TraderPrime _currentTradeShip;
private bool _initComplete;
private string _hasSpawned = "false";
private bool _initComplete;
#endregion
#region ctor
......@@ -58,6 +54,12 @@ namespace Glitterworld_Prime
internal bool HasSentThingListYet { get; set; }
internal bool HasSpawned
{
get { return _hasSpawned == "true"; }
set { _hasSpawned = value ? "true" : "false"; }
}
#endregion
#region Methods
......@@ -104,12 +106,6 @@ namespace Glitterworld_Prime
OrderTracker.Tick();
}
internal bool HasSpawned
{
get { return _hasSpawned == "true"; }
set { _hasSpawned = value ? "true" : "false"; }
}
internal void SetTraderShipGoods(List<GlitterWorldItem> items)
{
_currentTradeShip.AddGoodsFromServer(items);
......@@ -123,10 +119,7 @@ namespace Glitterworld_Prime
switch (VersionControl.CurrentMajor)
{
case 0:
if (VersionControl.CurrentMinor != 19)
{
throw new InvalidOperationException("Unsupported version!");
}
if (VersionControl.CurrentMinor != 19) throw new InvalidOperationException("Unsupported version!");
GlitterWorldApi.MarketUrl = "m1";
break;
......@@ -138,7 +131,7 @@ namespace Glitterworld_Prime
default:
throw new InvalidOperationException("Unsupported version!");
}
LogWriter.WriteMessage($"Game version is {GlitterWorldApi.MarketUrl}");
Utilities.SetupSsl();
......
......@@ -44,14 +44,11 @@ namespace Glitterworld_Prime
internal static void WriteMessage(string message, StackFrame sf = null)
{
if (sf == null)
{
sf = new StackTrace().GetFrame(1);
}
if (sf == null) sf = new StackTrace().GetFrame(1);
Log.Message($"{Prefix} -> {sf.GetMethod().DeclaringType?.Name}.{sf.GetMethod().Name} -> {message}");
}
#endregion
}
}
}
\ No newline at end of file
......@@ -188,4 +188,4 @@ namespace Glitterworld_Prime
#endregion
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region License
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, Translation.cs, Created 2019-02-13
#endregion
using Harmony;
using Verse;
......@@ -9,15 +14,23 @@ namespace Glitterworld_Prime.Patches
{
public class Translation
{
#region Nested type: TextPatch
[HarmonyPatch(typeof(DebugThingPlaceHelper))]
[HarmonyPatch("DebugSpawn")]
public class TextPatch
{
#region Methods
public static void Prefix(ThingDef def, IntVec3 c, int stackCount = -1, bool direct = false)
{
var mapComponent = Find.CurrentMap.GetComponent<GlitterWorld_MapComponent>();
mapComponent.HasSpawned = true;
}
#endregion
}
#endregion
}
}
}
\ No newline at end of file
......@@ -41,4 +41,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
\ No newline at end of file
#region License
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, DumpThingData.cs, Created 2018-11-08
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Glitterworld_Prime.ApiStructs;
using RimWorld;
using Verse;
using SimpleJson = RestSharp.SimpleJson;
namespace Glitterworld_Prime.Tools
{
internal static class DumpThingData
{
#region Methods
private static void setQuality(Thing thing, QualityCategory quality)
{