Family:Create

From Intrigues Wiki
Revision as of 07:35, 3 March 2024 by Tayfunwiki (talk | contribs) (Created page with "= Family Creation = == Overview == The <code>Family</code> class provides methods to create and manage families with specific attributes. This documentation explains how to use the <code>Create</code> method, detailing its parameters, return types, and providing example implementations for creating families. == Create Method Variants == The <code>Create</code> method has two variants, each designed to accommodate different scenarios for specifying family attributes, su...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Family Creation

Overview

The Family class provides methods to create and manage families with specific attributes. This documentation explains how to use the Create method, detailing its parameters, return types, and providing example implementations for creating families.

Create Method Variants

The Create method has two variants, each designed to accommodate different scenarios for specifying family attributes, such as culture.

Variant 1: Create with Direct Object References

Description

Creates a new family with specific attributes using direct object references for the culture. It is the preferred method when you have a direct reference to the culture object.

Signature

public static Family Create(string familyName, string description, Culture culture = null, Sprite icon = null)

Parameters

  • familyName (string): The name of the family.
  • description (string): A description of the family's history, values, or notable characteristics.
  • culture (Culture, optional): The culture associated with the family.
  • icon (Sprite, optional): A visual representation (banner) of the family.

Returns

If a family with the same name exists, it returns the existing family; otherwise, it creates and returns a new family.

Example Usage

using Nullframes.Intrigues;
using UnityEngine;

public class Runtime : MonoBehaviour {

    public Sprite icon;

    private void Start() {
        CreatePlayerFamily();
    }

    public void CreatePlayerFamily() {
        Family family = Family.Create("Frostborn", "Description", IM.Player.Culture, icon);
        
        IM.Player.JoinFamily(family);
    }
}

Variant 2: Create with Culture by Name or ID

Description

Facilitates family creation using the name or ID for culture instead of a direct object reference. This method is useful when you prefer to reference culture by an identifier.

Signature

public static Family Create(string familyName, string description, string cultureNameOrId, Sprite icon)

Parameters

  • familyName (string): The name of the family.
  • description (string): A description of the family's history, values, or notable characteristics.
  • cultureNameOrId (string): The name or ID of the culture associated with the family.
  • icon (Sprite): A visual representation (banner) of the family.

Returns

If a family with the same name exists, it returns the existing family; otherwise, it creates and returns a new family.

Example Usage

using Nullframes.Intrigues;
using UnityEngine;

public class Runtime : MonoBehaviour {

    public Sprite icon;

    private void Start() {
        CreatePlayerFamily();
    }

    public void CreatePlayerFamily() {
        Family family = Family.Create("Frostborn", "Description", "Varag", icon);
        
        IM.Player.JoinFamily(family);
    }
}

Remarks

  • Uniqueness Check: Both method variants check for the existence of a family with the provided name to ensure uniqueness. If an existing family is found, it returns the existing family to prevent duplication.
  • Debug Logging: A debug message is logged if an attempt is made to create a family with a name that already exists within the system. This aids in debugging and maintaining the integrity of the family system.
  • Culture Validation: For the second variant, where culture is specified by name or ID, the method includes validation to ensure the specified culture exists within the system before creating the family.
  • Error Handling: Implementing error handling around the Create method is recommended, especially for the second variant, to deal with scenarios where the specified culture does not exist.