본문으로 건너뛰기

다른 테이블 가리키기

시트가 코드가 되는 모습으로


:type 칸에 foreign <테이블> 이라고 적으면 그 컬럼은 숫자가 아니라 저 테이블의 행입니다. 셀에는 대상의 키를 적습니다.

가장 단순한 꼴입니다 — 컬럼 하나가 저쪽 테이블의 행 하나를 가리킵니다.

테이블 Shop

테이블 ShopEntry

[System.Serializable]
public partial class ShopEntryRecord
{
#region Values
/// <summary>
/// primary index
/// </summary>
public int Index => _index;

/// <summary>
/// which shop
/// </summary>
public int ShopId => _shopId_Shop_index;
public ShopRecord ShopByShopId => _shopId;

/// <summary>
/// which potion
/// </summary>
public int PotionId => _potionId_Potion_index;
public PotionRecord PotionByPotionId => _potionId;

/// <summary>
/// how many
/// </summary>
public int Stock => _stock;
#endregion

#region Reference wiring
public void SetReference_ShopId_INTERNAL(ShopRecord value) => _shopId = value;
public void SetReference_PotionId_INTERNAL(PotionRecord value) => _potionId = value;
#endregion

#region Storage
internal int _index;
internal ShopRecord _shopId;
internal int _shopId_Shop_index;
internal PotionRecord _potionId;
internal int _potionId_Potion_index;
internal int _stock;
#endregion

#region ToString
public override string ToString()
{
var sb = new StringBuilder("{");
sb.Append("\"Index\":"); ToStringHelper.ToString(Index, sb);
sb.Append(",\"ShopId\":"); ToStringHelper.ToString(ShopId, sb);
sb.Append(",\"PotionId\":"); ToStringHelper.ToString(PotionId, sb);
sb.Append(",\"Stock\":"); ToStringHelper.ToString(Stock, sb);
sb.Append("}");
return sb.ToString();
}
#endregion
}

ShopEntryTable.cs

컬럼 하나가 멤버 둘이 됩니다.

  • ShopId — 셀에 적힌 키 그대로입니다
  • ShopByShopId — 그 키가 가리키는 행입니다

이름은 <대상>By<컬럼> 으로 만들어집니다 (참조가 내는 이름).

파일에는 키로 저장되고, 모든 테이블을 읽은 뒤에 실제 레코드로 연결됩니다. 그래서 가리킨 행의 값을 쓸 때 조회를 한 번 더 하지 않습니다entry.ShopByShopId.Name 이 곧 상점 이름입니다.


참조가 취하는 꼴은 넷입니다.

적는 법
foreign Potion그 테이블의 행 하나
foreign Potion.Name그 행의 값 하나 — 컬럼의 타입은 저쪽 컬럼의 타입이 됩니다
foreign Potion[]행 여럿
foreign Potion?행 하나, 또는 없음

테이블 Craft

[System.Serializable]
public partial class CraftRecord
{
#region Values
/// <summary>
/// primary index
/// </summary>
public int Index => _index;

/// <summary>
/// a whole row
/// </summary>
public int Result => _result_Potion_index;
public PotionRecord PotionByResult => _result;

/// <summary>
/// one of its values
/// </summary>
public string ResultName => _resultName;

/// <summary>
/// several rows in one cell
/// </summary>
public int[] Parts => _parts_Potion_index;
public PotionRecord[] PotionByParts => _parts;

/// <summary>
/// a row, or none
/// </summary>
public int Substitute => _substitute_Potion_index;
public PotionRecord PotionBySubstitute => _substitute;
/// <summary>Whether this row has a value for <see cref="Substitute"/>.</summary>
public bool HasSubstitute => _substituteHasValue;
#endregion

#region Reference wiring
public void SetReference_Result_INTERNAL(PotionRecord value) => _result = value;
public void SetReference_ResultName_INTERNAL(string value) => _resultName = value;
public void SetReference_Parts_INTERNAL(int index, PotionRecord value) => _parts[index] = value;
public void SetReference_Substitute_INTERNAL(PotionRecord value) => _substitute = value;
#endregion

#region Storage
internal int _index;
internal PotionRecord _result;
internal int _result_Potion_index;
internal string _resultName;
public int _resultName_Potion_index;
internal PotionRecord[] _parts = System.Array.Empty<PotionRecord>();
internal int[] _parts_Potion_index = System.Array.Empty<int>();
internal PotionRecord _substitute;
internal int _substitute_Potion_index;
internal bool _substituteHasValue;
#endregion

#region ToString
public override string ToString()
{
var sb = new StringBuilder("{");
sb.Append("\"Index\":"); ToStringHelper.ToString(Index, sb);
sb.Append(",\"Result\":"); ToStringHelper.ToString(Result, sb);
sb.Append(",\"ResultName\":"); ToStringHelper.ToString(ResultName, sb);
sb.Append(",\"Parts\":"); ToStringHelper.ToString(Parts, sb);
sb.Append(",\"Substitute\":"); ToStringHelper.ToString(Substitute, sb);
sb.Append("}");
return sb.ToString();
}
#endregion
}

CraftTable.cs

ResultName 이 문자열인 것이 읽을 자리입니다. 셀에는 키를 적었지만 타입은 저쪽 컬럼을 따라갑니다 — 가리키는 것이 행이 아니라 그 행의 값이기 때문입니다.

배열도 옵셔널도 같은 규칙으로 이름이 둘씩 생깁니다.