Skip to content

Commit

Permalink
Functional Intial 1.5 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lilwhitemouse committed Apr 30, 2024
1 parent fd01319 commit c8f73e7
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 124 deletions.
93 changes: 68 additions & 25 deletions DeepStorage/CompDeepStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@
namespace LWM.DeepStorage
{
public class CompDeepStorage : ThingComp, IExposable, IHoldMultipleThings.IHoldMultipleThings, IRenameable {
public string label = "";
public string RenamableLabel
{
get => this.buildingLabel.NullOrEmpty() ? this.BaseLabel : this.buildingLabel;
set => this.label = value;TODO
}

public string BaseLabel => this.parent.def.label.CapitalizeFirst();

public string InspectLabel => this.RenamableLabel;
public override IEnumerable<Gizmo> CompGetGizmosExtra() {
foreach (Gizmo g in base.CompGetGizmosExtra()) {
yield return g;
Expand Down Expand Up @@ -321,14 +311,63 @@ public bool StackableAt(Thing thing, IntVec3 cell, Map map) {
return map.GetComponent<MapComponentDS>().CanStoreItemAt(this, thing, cell);
//return this.CapacityToStoreThingAt(thing,map,cell) > 0;
}
/****************************** IRenamable interface *****************************/
/* Because the dev team copies my good ideas, so all the stuff I did to rename */
/* groups of deep storage items might as well become part of IRenamable */
/*********************************************************************************/
public override void PostExposeData() { // why not call it "ExposeData" anyway?
public string RenamableLabel
{
get => this.buildingLabel.NullOrEmpty() ? this.BaseLabel : this.buildingLabel;
set {
if (parent is IStorageGroupMember isgm)
{
if (isgm.Group == null)
{

}
}
string newLabel = value ?? "";
/*
if ((parent is IStorageGroupMember storage) && storage.Group != null)
{
foreach (var c in DSStorageGroupUtility.GetDSCompsFromGroup(storage.Group))
{
c.SetLabelDirect(newLabel);
}
}
else SetLabelDirect(newLabel);
*/
}
}

public string BaseLabel => this.parent.def.label.CapitalizeFirst();

public string InspectLabel => this.RenamableLabel;

/*********************************************************************************/
public override void PostExposeData() { // ExposeData from inside a ThingWithComps
Scribe_Values.Look<string>(ref buildingLabel, "LWM_DS_DSU_label", "", false);
Scribe_Values.Look<int?>(ref maxNumberStacks, "LWM_DS_DSU_maxNumberStacks", null, false);
}
public void ExposeData() // Because ExposeData is a special IExposable thing!
public void ExposeData() // ExposeData when the comp must be saved on its own
{
PostExposeData();
Scribe_References.Look(ref parent, "LWM_DS_Comp_Parent");
// Save def of compproperties: (otherwise, we won't have this info, because this doesn't come from a ThingWithComps)
string dn;
if (Scribe.mode == LoadSaveMode.Saving)
{
dn = CdsProps?.parent.defName;
Scribe_Values.Look<string>(ref dn, "LWM_DS_Comp_CdsPropDefName");
}
// When loading, LoadingVars is when we'll get the value from Look and we can properly
// set up the comp:
if (Scribe.mode == LoadSaveMode.LoadingVars)
{
dn = null;
Scribe_Values.Look<string>(ref dn, "LWM_DS_Comp_CdsPropDefName");
this.props = DefDatabase<ThingDef>.GetNamed(dn).GetCompProperties<DeepStorage.Properties>();
}
}
/********************** properties **********************/
public Properties CdsProps // b/c I hate typing :p
Expand All @@ -345,7 +384,7 @@ public int MinNumberStacks
}
public int MaxNumberStacks
{
get {
get { // Note: Will need a CalculatedMaxNumberStacks too if we ever let masterwork/legendary add more stacks
return maxNumberStacks ?? ((Properties)this.props).maxNumberStacks;
}
set {
Expand Down Expand Up @@ -374,25 +413,26 @@ public virtual bool ShowContents
}
}

public void SetLabel(string newLabel)
/* [Multiplayer.API.SyncMethod]
private void SetLabelDirect(string newLabel)
{
buildingLabel = newLabel;
}
*/
public void ResetSettings()
{
if (newLabel == null) newLabel = "";
if ((parent is IStorageGroupMember storage) && storage.Group != null)
{
foreach (var c in DSStorageGroupUtility.GetDSCompsFromGroup(storage.Group)) {
c.SetLabelDirect(newLabel);
foreach (var c in DSStorageGroupUtility.GetDSCompsFromGroup(storage.Group))
{
c.ResetSettingsDirect();
}
}
else SetLabelDirect(newLabel);
}
[Multiplayer.API.SyncMethod]
private void SetLabelDirect(string newLabel)
{
buildingLabel = newLabel;
else ResetSettingsDirect();
}

[Multiplayer.API.SyncMethod]
public virtual void ResetSettings()
public void ResetSettingsDirect()
{
this.buildingLabel = "";
this.maxNumberStacks = null;
Expand All @@ -401,8 +441,11 @@ public virtual void ResetSettings()

public void CopySettingsFrom(CompDeepStorage other)
{
SetLabelDirect(other.buildingLabel);
Log.Message("Is the other null?" + (other == null));
Log.Message("If not: " + other.parent);
// SetLabelDirect(other.buildingLabel);
SetMaxNumberStacksDirect(other.maxNumberStacks);
Log.Message("Pkay then");
}

public string buildingLabel="";
Expand Down
12 changes: 7 additions & 5 deletions DeepStorage/Deep_Storage_CanCarryItemsTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,18 @@ static bool Prepare(Harmony instance)
static void Postfix(ref bool __result, IntVec3 c, Map map, Pawn carrier)
{
if (__result == false) return;
if (carrier?.RaceProps == null) return; // Don't know what it is, but let it pass
// If it's smart enough, don't bother looking further:
if (carrier.RaceProps.intelligence >= NecessaryIntelligenceToUseDeepStorage)
return;
if (specialTest != null && specialTest(carrier)) return; // passes specialTest?

// Check if deep storage restrictions even apply here - if it's to a regular shelf,
// or to a stockpile, for example, we shouldn't be futzing with it:
if (LWM.DeepStorage.Utils.CanStoreMoreThanOneThingAt(map, c))
{
{ // But if it IS in Deep Storage, we know it can't use it, so fail:
__result = false;
}
if (specialTest != null && specialTest(carrier)) return; // passes specialTest?
if (carrier?.RaceProps == null) return;
if (carrier.RaceProps.intelligence >= NecessaryIntelligenceToUseDeepStorage)
return; // smart enough to use whatever.
return;
}
}
Expand Down
Loading

0 comments on commit c8f73e7

Please sign in to comment.