Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutogenUI Example #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions Examples/AltRecipe/Server/Mods/UserCode/ExoticSaladAlt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@
// See LICENSE file in the project root for full license information.
// <auto-generated />

using Eco.Gameplay.Components;
using Eco.Gameplay.Items.Recipes;
using Eco.Gameplay.Skills;
using Eco.Shared.Localization;

namespace Eco.Mods.TechTree
{
using System;
using System.Collections.Generic;
using Eco.Gameplay.Components;
using Eco.Gameplay.DynamicValues;
using Eco.Gameplay.Items;
using Eco.Gameplay.Players;
using Eco.Gameplay.Skills;
using Eco.Shared.Utils;
using Eco.World;
using Eco.World.Blocks;
using Gameplay.Systems.TextLinks;
using Eco.Shared.Localization;

/// <summary>
/// <para>An example alternative server side recipe definition for "ExoticSalad". This recipe can be crafted at a Campfire instead of a Iron Stove.</para>
/// <para>More information about RecipeFamily objects can be found at https://docs.play.eco/api/server/eco.gameplay/Eco.Gameplay.Items.RecipeFamily.html</para>
Expand All @@ -37,7 +29,7 @@ public ExoticSaladAltRecipe()
{
new IngredientElement(typeof(PricklyPearFruitItem), 6, typeof(CookingSkill), typeof(CookingLavishResourcesTalent)),
new IngredientElement(typeof(CriminiMushroomsItem), 6, typeof(CookingSkill), typeof(CookingLavishResourcesTalent)),
new IngredientElement(typeof(RiceItem), 6, typeof(CookingSkill), typeof(CookingLavishResourcesTalent)),
new IngredientElement(typeof(RiceItem), 6, typeof(CookingSkill), typeof(CookingLavishResourcesTalent)),
},

// Define our recipe output items.
Expand Down
94 changes: 94 additions & 0 deletions Examples/AutogenUI/Server/ComponentInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using Eco.Core.Controller;
using Eco.Core.PropertyHandling;
using Eco.Gameplay.Objects;
using Eco.Shared.Localization;
using Eco.Shared.Networking;
using Eco.Shared.Serialization;

namespace Eco.Mods.Components
{
[Serialized]
[AutogenClass]
[LocDisplayName("Component Interface")]
[LocDescription("An example interface for a component.")]
[NoIcon]
[CreateComponentTabLoc("Interface")]
public partial class ComponentInterfaceExample : WorldObjectComponent
{
// A read only property formated into a LocString

[LocDisplayName("Readonly Property"), LocDescription("This property is readonly.")]
[SyncToView, Notify, Autogen] public string ReadonlyPropertyDisplay => Localizer.DoStr($"This property is set to {ChangingProperty}."); // formats the value into a string
// Called when a user trys to set the value. Only updates value to ensure ui is up to date.
[RPC] public void SetReadonlyPropertyDisplay(string value) => this.FirePropertyChanged(nameof(ReadonlyPropertyDisplay));

[Serialized] private float _ChangingProperty = 0;
public float ChangingProperty
{
get => _ChangingProperty;
set
{
if (_ChangingProperty == value) return;
// Fires all displays that use this value to update the client
this.FirePropertyChanged(nameof(ReadonlyPropertyDisplay));

_ChangingProperty = value;
}
}

// A read only property as raw

[Serialized] private float _ChangingProperty_2 = 0;

[LocDisplayName("Readonly Raw Property"), LocDescription("This property is readonly from its raw value format.")]
[SyncToView, Notify, Autogen] public float ChangingProperty_2
{
get => _ChangingProperty_2;
set
{
if (_ChangingProperty_2 == value) return;
// Fires all displays that use this value to update the client
this.FirePropertyChanged(nameof(ChangingProperty_2));

_ChangingProperty_2 = value;
}
}
[RPC] public void SetChangingProperty_2(string value) => this.FirePropertyChanged(nameof(ChangingProperty_2));

// A static property

[LocDisplayName("Static Property"), LocDescription("This property is static and wont update.")]
[SyncToView, Notify, Autogen] public string StaticPropertyDisplay => Localizer.DoStr($"This property is set to {Property}."); // formats the value into a string
// Called when a user trys to set the value. Does nothing to ensure its read only.
[RPC] public void SetStaticPropertyDisplay(string value) => this.FirePropertyChanged(nameof(StaticPropertyDisplay));

public float Property => 18;

// A editable property

[Serialized] private string _Words = Localizer.DoStr("Potato");

[LocDisplayName("Editable Words"), LocDescription("This property can be changed per your will.")]
[SyncToView, Notify, Autogen]
public string Words
{
get => _Words;
set
{
if (_Words == value) return;
// Fires all displays that use this value to update the client
this.FirePropertyChanged(nameof(Words));

_Words = value;
}
}
[RPC] public void SetWords(string value) => Words = value;

public override void Tick()
{
ChangingProperty += 1;
ChangingProperty_2 -= 1.5f;
base.Tick();
}
}
}
49 changes: 20 additions & 29 deletions Examples/Blockset/Server/StainedGlass.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
namespace Eco.Mods.TechTree
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Eco.Gameplay.Blocks;
using Eco.Gameplay.Components;
using Eco.Gameplay.DynamicValues;
using Eco.Gameplay.Items;
using Eco.Gameplay.Objects;
using Eco.Gameplay.Players;
using Eco.Gameplay.Skills;
using Eco.Gameplay.Systems;
using Eco.Gameplay.Systems.TextLinks;
using Eco.Core.Items;
using Eco.Shared.Localization;
using Eco.Shared.Serialization;
using Eco.Shared.Utils;
using Eco.World;
using Eco.World.Blocks;
using Eco.Gameplay.Pipes;
using Eco.Gameplay.Blocks;
using Eco.Gameplay.Components;
using Eco.Gameplay.Items;
using Eco.Gameplay.Objects;
using Eco.Gameplay.Skills;
using Eco.Core.Items;
using Eco.Shared.Localization;
using Eco.Shared.Serialization;
using Eco.World.Blocks;
using Eco.Gameplay.Items.Recipes;

namespace Eco.Mods.TechTree
{
[RequiresSkill(typeof(GlassworkingSkill), 1)]
public partial class GreenStainedGlassRecipe : RecipeFamily
{
Expand Down Expand Up @@ -66,16 +57,16 @@ public partial class GreenStainedGlassBlock : Block, IRepresentsItem

[Serialized]
[LocDisplayName("Green Stained Glass")]
[LocDescription("A transparent, solid material useful for more than just windows.")]
[MaxStackSize(20)]
[Weight(10000)]
[Ecopedia("Blocks", "Building Materials", createAsSubPage: true, display: InPageTooltip.DynamicTooltip)]
[Ecopedia("Blocks", "Building Materials", createAsSubPage: true, displayOnPage: true)]
[Currency][Tag("Currency")]
[Tag("Constructable", 1)]
[Tag("Constructable")]
[Tier(2)]
public partial class GreenStainedGlassItem : BlockItem<GreenStainedGlassBlock>
{
public override LocString DisplayNamePlural { get { return Localizer.DoStr("Green Stained Glass"); } }
public override LocString DisplayDescription { get { return Localizer.DoStr("A transparent, solid material useful for more than just windows."); } }
public override LocString DisplayNamePlural { get { return Localizer.DoStr("Green Stained Glass"); } }

public override bool CanStickToWalls { get { return false; } }

Expand All @@ -88,10 +79,10 @@ public partial class GreenStainedGlassItem : BlockItem<GreenStainedGlassBlock>
public override Type[] BlockTypes { get { return blockTypes; } }
}

[Serialized, Solid] public class GreenStainedGlassStacked1Block : PickupableBlock { }
[Serialized, Solid] public class GreenStainedGlassStacked2Block : PickupableBlock { }
[Serialized, Solid] public class GreenStainedGlassStacked3Block : PickupableBlock { }
[Serialized, Solid,Wall] public class GreenStainedGlassStacked4Block : PickupableBlock { } //Only a wall if it's all 4 Glass
[Serialized, Solid] public class GreenStainedGlassStacked1Block : PickupableBlock { }
[Serialized, Solid] public class GreenStainedGlassStacked2Block : PickupableBlock { }
[Serialized, Solid] public class GreenStainedGlassStacked3Block : PickupableBlock { }
[Serialized, Solid, Wall] public class GreenStainedGlassStacked4Block : PickupableBlock { } //Only a wall if it's all 4 Glass

[Serialized]
[Wall, Constructed, Solid, BuildRoomMaterialOption]
Expand Down
24 changes: 10 additions & 14 deletions Examples/CornOnTheCob/Server/CornOnTheCob.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Eco.Core.Items;
using Eco.Core.Items;
using Eco.Gameplay.Components;
using Eco.Gameplay.Items;
using Eco.Gameplay.Items.Recipes;
using Eco.Gameplay.Players;
using Eco.Gameplay.Skills;
using Eco.Shared.Localization;
Expand All @@ -14,18 +10,18 @@
namespace Eco.Mods.TechTree
{
[Serialized]
[LocDisplayName("Corn on the cob")]
[Weight(300)]
[Tag("BakedVegetable", 1)]
[Tag("BakedFood", 1)]
[Tag("BakedFood")]
[Tag("BakedVegetable")]
[LocDisplayName("Corn on the cob")]
[LocDescription("A warmly colored kernel studded vegetable.")]
public partial class CornOnTheCobItem : FoodItem
{
public override LocString DisplayNamePlural => Localizer.DoStr("Corn on the Cob ");
public override LocString DisplayDescription => Localizer.DoStr("A warmly colored kernel studded vegetable.");
public override Nutrients Nutrition => new Nutrients { Carbs = 12, Fat = 2, Protein = 3, Vitamins = 11};
public override LocString DisplayNamePlural => Localizer.DoStr("Corn on the Cob ");
public override Nutrients Nutrition => new Nutrients { Carbs = 12, Fat = 2, Protein = 3, Vitamins = 11};

public override float Calories => 250;
public override int ShelfLife => 86000;
public override float Calories => 250;
protected override float BaseShelfLife => 86000;

}

Expand Down
65 changes: 27 additions & 38 deletions Examples/Flag/Server/FlagObject.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,51 @@
namespace Eco.Mods.TechTree
{
using Eco.Gameplay.Components;
using Eco.Gameplay.Components.Auth;
using Eco.Gameplay.Items;
using Eco.Shared.Localization;
using Eco.Gameplay.Objects;
using Eco.Shared.Serialization;
using Eco.Shared.Math;
using System.Collections.Generic;
using Eco.Core.Items;
using Eco.Gameplay.Players;

using Eco.Gameplay.Components;
using Eco.Gameplay.Components.Auth;
using Eco.Gameplay.Items;
using Eco.Shared.Localization;
using Eco.Gameplay.Objects;
using Eco.Shared.Serialization;
using Eco.Shared.Math;
using Eco.Core.Items;
using Eco.Gameplay.Occupancy;
using Eco.Gameplay.Items.Recipes;

namespace Eco.Mods.TechTree
{
[Serialized]
[RequireComponent(typeof(SolidGroundComponent))]
[RequireComponent(typeof(RoomRequirementsComponent))]
[LocDisplayName("Test Flag")]
[RequireComponent(typeof(OnOffComponent))]
[RequireComponent(typeof(PropertyAuthComponent))]
public partial class FlagObject : WorldObject
public partial class FlagObject : WorldObject, IRepresentsItem
{
public override LocString DisplayName { get { return Localizer.DoStr("Test Flag"); } }
public bool isRoom { get; set; }
protected override void Initialize()
{

}
public virtual Type RepresentedItemType => typeof(FlagItem);

public override void Destroy()
{
base.Destroy();
}
// Runs on object placement/load before its first tick.
protected override void Initialize() => base.Initialize();
protected override void PostInitialize() => base.PostInitialize();

protected override void PostInitialize()
{
base.PostInitialize();
}
// Runs before the destruction of the object in world.
protected override void OnDestroy() => base.OnDestroy();

}

[Serialized]
[LocDisplayName("Test Flag")]
[Ecopedia("Housing Objects", "Flags", createAsSubPage: true, display: InPageTooltip.DynamicTooltip)]
[LocDisplayName("Test Flag")] // Allows you to change the name the player sees for this item
[LocDescription("A piece of fabric with something on it. can be used for decorating.")] // The tooltip discription of the item.
[Ecopedia("Housing Objects", "Flags", createAsSubPage: true, DisplayOnPage = true)] // Creates a new subpage in Flags in the Housing Objects section for this item.
[Weight(10)]
public partial class FlagItem : WorldObjectItem<FlagObject>
{
public override LocString DisplayDescription { get { return Localizer.DoStr("A piece of fabric with something on it. can be used for decorating."); } }

static FlagItem()
{
// Adds occupancy to the object in all the blocks listed in orentation of the root (front left bottom)
WorldObject.AddOccupancy<FlagObject>(new List<BlockOccupancy>(){
new BlockOccupancy(new Vector3i(0, 0, 0)),
new BlockOccupancy(new Vector3i(0, 1, 0)),
new(new Vector3i(0, 0, 0)),
new(new Vector3i(0, 1, 0)),
});
}
}

public partial class FlagRecipe :
RecipeFamily
public partial class FlagRecipe : RecipeFamily
{
public FlagRecipe()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/*
*
*
*/

using Eco.Core.Plugins.Interfaces;
using Eco.Core.Plugins.Interfaces;
using Eco.Core.Utils;
using Eco.Gameplay.Aliases;
using Eco.Gameplay.GameActions;
using Eco.Gameplay.Property;
using Eco.Gameplay.Systems.Messaging.Notifications;
using Eco.Shared.Localization;
using System.Threading.Tasks;

namespace Eco.Examples.GameActionListener
{
Expand All @@ -20,7 +16,8 @@ namespace Eco.Examples.GameActionListener
public class GarbageDetectionPlugin : IModKitPlugin, IGameActionAware, IInitializablePlugin, IShutdownablePlugin
{
/// <summary>Retrieves the current status of the <see cref="IModKitPlugin"/>.</summary>
public string GetStatus() => "Ready!";
public string GetStatus() => "Ready!";
public string GetCategory() => "Mods";

#region IInitializablePlugin/IShutdownablePlugin Interface
/// <summary>Called on plugin instantiation to register our selves with the <see cref="ActionUtil"/> listeners.</summary>
Expand Down Expand Up @@ -60,6 +57,16 @@ public void ActionPerformed(GameAction action)
/// <param name="action">The <see cref="GameAction"/> being performed. This variable can be compared against the interfaces and defined action models to find out what is being processed.</param>
/// <returns>The <see cref="LazyResult"/> containing the modified authorization result.</returns>
public LazyResult ShouldOverrideAuth(GameAction action) => LazyResult.Succeeded; // Don't change the authorization behaviour of this action

void IGameActionAware.ActionPerformed(GameAction action)
{
throw new NotImplementedException();
}

LazyResult ICanOverrideAuth.ShouldOverrideAuth(IAlias? alias, IOwned? property, GameAction? action)
{
throw new NotImplementedException();
}
#endregion
}
}
3 changes: 2 additions & 1 deletion Examples/ModkitPlugin/ModkitPlugin/WelcomeUserPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Eco.Gameplay.Players;
using Eco.Shared.Localization;
using Eco.Shared.Utils;
using System.Threading.Tasks;

namespace Eco.WelcomePlugin
{
Expand Down Expand Up @@ -92,5 +91,7 @@ public void OnEditObjectChanged(object o, string param) { }

/// <summary>Custom ToString override for properly naming our plugin into the Eco server UI</summary>
public override string ToString() => "Welcome User";

string IServerPlugin.GetCategory() => "Mods";
}
}