MCPcopy Create free account
hub / github.com/KikoPlayProject/KikoPlay / getDanmu

Method getDanmu

Extension/Script/danmuscript.cpp:70–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70ScriptState DanmuScript::getDanmu(const DanmuSource *item, DanmuSource **nItem, QVector<DanmuComment *> &danmuList)
71{
72 MutexLocker locker(scriptLock);
73 if(!locker.tryLock()) return ScriptState(ScriptState::S_BUSY);
74 QString errInfo;
75 QVariantList rets = call(luaDanmuFunc, {item->toMap()}, 2, errInfo);
76 if(!errInfo.isEmpty()) return ScriptState(ScriptState::S_ERROR, errInfo);
77 if((rets[0].type()!=QVariant::Map && rets[0].type()!=QVariant::Invalid) || rets[1].type()!=QVariant::List) return ScriptState(ScriptState::S_ERROR, "Wrong Return Value Type");
78 if(rets[0].type() == QVariant::Invalid)
79 {
80 *nItem = nullptr;
81 }
82 else if(rets[0].type() == QVariant::Map)
83 {
84 DanmuSource *nSrc = new DanmuSource;
85 auto itemObj = rets[0].toMap();
86 *nSrc = *item;
87 nSrc->title = itemObj.value("title").toString();
88 nSrc->desc = itemObj.value("desc").toString();
89 nSrc->scriptData = itemObj.value("data").toString();
90 nSrc->duration = itemObj.value("duration", 0).toInt();
91 *nItem = nSrc;
92 }
93 auto dobjs = rets[1].toList(); //[{text=xx, time=xx(number, ms), <color=xx(int)>, <fontsize=xx(int, 1=normal, 2=small, 3=large)> <type=xx(int, 1=roll,2=top,3=bottom)>, <date=xx(str)>, <sender=xx>},....]
94 for(auto &d : dobjs)
95 {
96 auto dobj = d.toMap();
97 QString text = dobj.value("text").toString();
98 double time = dobj.value("time", -1).toDouble();
99 if(text.isEmpty() || time<0) continue;
100 DanmuComment *comment = new DanmuComment;
101 comment->text = text;
102 comment->time = comment->originTime = time;
103 comment->color = dobj.value("color", 0xFFFFFF).toInt();
104 int fontsize = dobj.value("fontsize", 0).toInt();
105 comment->fontSizeLevel = (fontsize == 1? DanmuComment::Small:(fontsize == 2? DanmuComment::Large : DanmuComment::Normal));
106 int type = dobj.value("type", (int)DanmuComment::Rolling).toInt();
107 comment->type = (DanmuComment::DanmuType)type;
108 comment->date = dobj.value("date", 0).toLongLong();
109 comment->sender = dobj.value("sender").toString();
110 danmuList.append(comment);
111 }
112 return ScriptState(ScriptState::S_NORM);
113}
114
115bool DanmuScript::supportURL(const QString &url)
116{

Callers

nothing calls this directly

Calls 8

ScriptStateClass · 0.85
valueMethod · 0.80
tryLockMethod · 0.45
toMapMethod · 0.45
isEmptyMethod · 0.45
typeMethod · 0.45
toStringMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected