karaoke-dev/karaoke

Able to get the reference amount in the `IHasPrimary` key proeprty.

Opened this issue · 10 comments

Found in the #2040 and #2057
We need to make sure that lyric should not be able to delete or split if the lyric is being referenced.

Maybe should make something like IHasReferenceElement interface and should implement the method like QueryAllReference(ElementId id) for able to get all the reference.

Those interface should be implemented in the:

  • KaraokeBeatmap
  • Stage and stage element.
  • Lyric
  • Note

Also note that QueryAllReference() in the KaraokeBeatmap() should query the hit-object also.

Not very sure but should worth to make a think:

  • How to find the element ids that does not have the reference item(the item might be deleted.)

Not very sure should save all referenced items inside the class that contains IHasPrimaryKey?
But might be hard to handle the event like undo or redo

Or maybe return a big dictionary that has all the reference ids.

Or maybe this interface sounds like IHasFilterTerms in the o!f?

We collect list of ids and find the matched ids from the big Collection<KeyValuePair<ElementId, IHasReferenceElement>>

Maybe should use the attribute to mark all the properties that contains ElementId or IHasReferenceElement?
And write the algorithm together:
e.g.

var reference = ElementIdHelper.GetAllReference(beatmap);

or

var id = "abdcefd";
var reference = ElementIdHelper.GetAllReference(beatmap, id);

另外有一個問題需要想一下
目前 lyric/note 已經有 working property 的機制,會不會讓這兩邊有重複的邏輯?

或是說能不能根據 id 和 type 去搜尋所有 matched 的 instance?

還有一個問題需要想一下
reference amount 應該要抓到正確的參考才對
e.g. lyric singer ids 如果 element id 是 lyric 的 ID,就會有抓錯的問題。

maybe reference 是參考哪個 property 內的哪個 property, like:

public class Lyric
{
  [ReferenceProperty(namepf(Lyric))]
  public ElementId? ReferenceLyricId {get;set;}
}

但可能會有一些問題:

  1. ReferenceLyricId 是從哪邊過來(e.g. beatmap.hitObjects) 的定義並不明確。如果未來多個地方都可以存放 lyric,會有參考問題
  2. 有點過度設計,會和 beatmap processor 內做的事情很像

如果換成另外一種想法,把 karaoke beatmap 當作是一個資料庫,這些東西是 table:

  • Singer (And Singer state)
  • Lyric
  • StageElement
  • ClassicLyricTimingPoint

那做的東西就會是單純的從 table 上面提取資料。
可能只需要定義哪些物件 table (e.g. StageCategory, ClassicStageInfo, SingerInfo, KaraokeBeatmap or IBeatmap)
並且可以從裡面拿到哪種型態的 row?

Not very sure but seems we can use source generator to deal with that?