Files
test/Docs/chat-emoji-progress-summary.md
2026-05-25 10:33:40 +07:00

119 lines
4.7 KiB
Markdown

# Chat Emoji Progress Summary
## Scope
- Muc tieu: hoan thien luong chat co emoji (input -> send -> render TMP) cho Unity client.
- Ngu canh: du an dang chuyen doi tu C++ PC sang C# Unity, uu tien giong logic goc.
## Bugs Da Tim Thay Va Da Sua
- `AUICommon.FilterEmotionSet` bi crash `NullReferenceException`.
- Nguyen nhan: dung `Dictionary` enumerator sai (doc `Current` truoc `MoveNext`).
- Da sua: doi sang `while (it.MoveNext())`, them check null item.
- `UnmarshalEditBoxText` khong extract item nao.
- Nguyen nhan: `itemMask = 0`.
- Da sua: dung `ITEMMASK_ALL = ~0`.
- `EditBoxItemsSet` dung range item-code sai (`\u0001..\u0010`) gay vo toan bo parse/lookup.
- Nguyen nhan: constants local khong dong bo voi `AUICommon.AUICOMMON_ITEM_CODE_START/END` (`\uE000..\uE3FF`).
- Da sua:
- bo constants sai trong `EditBoxItemsSet`,
- dung range cua `AUICommon` cho check/next-char.
- Hien thi raw wire text trong TMP: `` + `<0><0:41>`.
- Nguyen nhan: wire format khong phai TMP rich text.
- Da sua:
- input chen `<sprite name="...">` neu resolve duoc,
- truoc khi gui convert `<sprite>` -> wire.
## Thay Doi Ve Architecture Emoji/TMP
- Ho tro nhieu bo emoji (9 bo) bang mapping theo set:
- `EmotionSetSpriteAssetEntry` (EmotionSetIndex -> TMP_SpriteAsset).
- `EmotionLibrarySpriteMap.SpriteAssetsPerEmotionSet`.
- `EmotionLibrarySpriteMap` da cap nhat:
- tra dung sprite asset theo `emotionSet`,
- fallback ve `TmpSpriteAsset` de tuong thich cau hinh cu,
- fallback ten `cell_XXXX` cho asset cu.
- Converter atlas dat ten sprite theo namespace:
- tu `cell_XXXX` -> `s{N}_cell_XXXX` (N = EmotionSetIndex),
- tranh trung ten khi gom nhieu pack vao TMP.
## Cac File Da Duoc Them/Sua
- Sua:
- `Assets/PerfectWorld/Scripts/Network/CSNetwork/AUICommon.cs`
- `Assets/Scripts/ChatInputHandler.cs`
- `Assets/Scripts/CECUIManager.cs`
- `Assets/PerfectWorld/Scripts/Chat/EmotionData/EmotionLibrarySpriteMap.cs`
- `Assets/PerfectWorld/Scripts/Editor/EmotionAtlasConverterCore.cs`
- `Assets/PerfectWorld/Scripts/Editor/EmotionAtlasConverterWindow.cs`
- Them moi:
- `Assets/PerfectWorld/Scripts/Chat/ChatInputTmpSpriteConverter.cs`
- `Assets/PerfectWorld/Scripts/Chat/EmotionData/EmotionSetSpriteAssetEntry.cs`
- `Assets/PerfectWorld/Scripts/Editor/EmotionLibrarySpriteMapEditor.cs`
- `Assets/Scripts/ChatEmojiQuickTest.cs`
## Class Test Nhanh
- `ChatEmojiQuickTest` da duoc tao de test local:
- nhap text + chen emoji,
- send va hien thi len `TextMeshProUGUI`,
- mo phong luong: TMP tag -> wire -> TMP display.
## Viec Can Setup Trong Unity (Bat Buoc)
- `EmotionLibrarySpriteMap`:
- gan `Library`,
- sync va gan du `SpriteAssetsPerEmotionSet` cho 9 bo.
- TMP asset:
- dam bao sprite naming khop (`s{N}_cell_XXXX`),
- setup fallback sprite assets de resolve du tat ca bo khi dung `<sprite name>`.
- Input/Output TMP:
- co sprite asset va fallback phu hop.
## Ket Qua Ky Vong
- Khong con crash tai `FilterEmotionSet`.
- Khong con hien raw wire text khi da qua conversion dung luong.
- Co the nhap emoji, gui len, va hien thi icon tren `TextMeshProUGUI` (neu setup asset dung).
## Cap nhat bug nghiem trong: chon set khac van ra emoji set 1 (2026-04-09)
- Hien tuong:
- Co 9 bo emoji.
- Chon emoji o set 1 thi dung.
- Chon set 2..8 van render hinh cua set 1.
- Nguyen nhan goc:
- Tag TMP dang tao dang `<sprite name="cell_XXXX">` (hoac `<sprite index=...>`), khong chi dinh ro `TMP_SpriteAsset`.
- Khi nhieu sprite asset deu co cung ten `cell_XXXX`, TMP uu tien asset mac dinh/fallback dau tien => thuong la set 1.
- Cach sua da ap dung:
- Them `SpriteAssetName` vao `EmotionSpriteInfo`.
- `EmotionLibrarySpriteMap.TryGetSprite(...)` tra them ten asset theo tung `emotionSet` (`set.TmpSpriteAsset.name`).
- `EmotionTMPTagBuilder.BuildSpriteTag(...)` tao tag co kem asset:
- `<sprite="Emotions N" name="cell_XXXX">`
- hoac `<sprite="Emotions N" anim="start,end,fps">`
- hoac `<sprite="Emotions N" index=N>`.
- `AUICommon.ConvertEmotionsToTMP(...)` dung chung `EmotionTMPTagBuilder.BuildSpriteTag(info)` de tat ca luong render dong nhat.
- File da sua cho fix nay:
- `Assets/PerfectWorld/Scripts/Network/CSNetwork/AUICommon.cs`
- `Assets/PerfectWorld/Scripts/Chat/EmotionTMPTagBuilder.cs`
- `Assets/PerfectWorld/Scripts/Chat/EmotionData/EmotionLibrarySpriteMap.cs`
- Dieu kien setup de hoat dong dung:
- Trong `EmotionLibrarySO`, moi `EmotionSetSnapshot` phai gan dung `TmpSpriteAsset` tuong ung tung set.
- Ten asset can on dinh, vi du `Emotions 0`, `Emotions 1`, ...; tag su dung chinh ten nay.
- Ket qua sau fix:
- Emoji duoc resolve dung theo `emotionSet`.
- Khong con tinh trang chon set khac nhung hien thi hinh cua set 1.