public ItemTranslation GetRandomTranslation() { IList <ItemTranslation> query = connection.Query <ItemTranslation>("SELECT * FROM ItemTranslation ORDER BY RANDOM() LIMIT 1"); ItemTranslation result = query.First(); return(result); }
public void SaveToHistory(ItemTranslation itemTranslation) { lock (locker) { itemTranslation.id = null; // Save this item to history connection.Insert(itemTranslation); } }
public void ReceiveNotification(ItemTranslation itemTranslation) { var args = new NotificationEventArgs() { Title = itemTranslation.German, Message = itemTranslation.English, }; NotificationReceived?.Invoke(null, args); var historyDatabaseController = new HistoryDatabaseController(); historyDatabaseController.SaveToHistory(itemTranslation); }
public void ReceiveNotification(ItemTranslation itemTranslation) { var args = new NotificationEventArgs() { Title = itemTranslation.German, Message = itemTranslation.English, }; NotificationReceived?.Invoke(null, args); // Save result to history db itemTranslation.id = null; var sqliteController = new AndroidSQLite(); var dbPath = sqliteController.GetPlatformDBPath("history.db3"); var connection = sqliteController.GetConnection(dbPath); connection.CreateTable <ItemTranslation>(); connection.Insert(itemTranslation); }
/// <summary> /// Initializes a new instance of the <see cref="ItemTranslations"/> class. /// </summary> public ItemTranslations() { var TranslationFiles = Directory.GetFiles(@"Gamefiles\translations\items\", "*.json"); if (TranslationFiles.Length > 0) { this.Translations = new Dictionary <string, Dictionary <string, ItemTranslation> >(TranslationFiles.Length); foreach (var TranslationFile in TranslationFiles) { string Language = Path.GetFileNameWithoutExtension(TranslationFile); if (string.IsNullOrEmpty(Language) == false) { var Content = File.ReadAllText(TranslationFile); var Json = JObject.Parse(Content); if (Json != null && Json.HasValues) { this.Translations.Add(Language, new Dictionary <string, ItemTranslation>()); foreach (var Item in Json) { var Translation = new ItemTranslation(); Translation.Load(Item.Value.ToObject <JObject>()); this.Translations[Language].Add(Item.Key, Translation); } } else { Log.Warning(this.GetType(), "Json is either null or don't have values at ItemTranslations()."); } } else { Log.Warning(this.GetType(), "Language key is empty at ItemTranslations()."); } } } else { Log.Warning(this.GetType(), "TranslationFiles.Length <= 0 at ItemTranslations()."); } }
void OnEnable() { if (ItemTranslation.itemsTr == null) { ItemTranslation.itemsTr = this; } else { Destroy(this.gameObject); } thisCanvas = gameObject.GetComponent <Canvas>(); videoPlane = thisCanvas.transform.GetChild(1).gameObject; speechBubbles = thisCanvas.transform.GetChild(0).GetComponent <Image>(); translationSpace = speechBubbles.transform.GetChild(0).GetComponent <Text>(); thisCanvas.enabled = false; videoPlane.SetActive(false); }
/// <summary> /// Tries to translate the specified key. /// </summary> /// <param name="Key">The key.</param> public bool TryTranslate(string Language, string Key, out ItemTranslation Translation) { if (this.Translations.ContainsKey(Language)) { if (this.Translations[Language].TryGetValue(Key, out Translation)) { return(true); } else { Log.Warning(this.GetType(), "Couldn't translate {" + Key + "} to " + Language + "."); } } else { Log.Warning(this.GetType(), "Couldn't translate {" + Key + "} to " + Language + "."); } Translation = null; return(false); }
private void DumpItems() { var items = new List <ItemTranslation>(); foreach (var type in _module.Types.Where( t => t.HasBaseType("Terraria.ModLoader.ModItem"))) { var item = new ItemTranslation { TypeName = type.Name, Namespace = type.Namespace }; var method = type.FindMethod("SetStaticDefaults", MethodSig.CreateInstance(_module.CorLibTypes.Void)); if (method?.HasBody == true) { var inst = method.Body.Instructions; for (var index = 0; index < inst.Count; index++) { var ins = inst[index]; if (ins.OpCode != OpCodes.Ldstr) { continue; } var value = ins.Operand as string; ins = inst[++index]; if (ins.Operand is IMethodDefOrRef m && string.Equals(m.Name.ToString(), "SetDefault") && string.Equals(m.DeclaringType.Name, "ModTranslation", StringComparison.Ordinal)) { ins = inst[index - 2]; if (!(ins?.Operand is IMethodDefOrRef propertyGetter)) { // some translation objects may get from stack; // In this case, we can't know their type. skip continue; } switch (propertyGetter.Name) { case "get_Tooltip": item.ToolTip = value; break; case "get_DisplayName": item.Name = value; break; } } } } method = type.FindMethod("ModifyTooltips"); if (method?.HasBody == true) { var inst = method.Body.Instructions; for (var index = 0; index < inst.Count; index++) { var ins = inst[index]; if (ins.OpCode != OpCodes.Newobj || !(ins.Operand is MemberRef m) || !m.DeclaringType.Name.Equals("TooltipLine")) { continue; } ins = inst[index - 1]; if (ins.OpCode.Equals(OpCodes.Ldstr) && inst[index - 2].OpCode.Equals(OpCodes.Ldstr)) { item.ModifyTooltips.Add(inst[index - 2].Operand as string); item.ModifyTooltips.Add(inst[index - 1].Operand as string); } else if (ins.OpCode.Equals(OpCodes.Call) && ins.Operand is MemberRef n && n.Name.Equals("Concat")) { var index2 = index; var count = 0; var total = n.MethodSig.Params.Count + 1; var list = new List <string>(); while (--index2 > 0 && count < total) { ins = inst[index2]; if (ins.OpCode.Equals(OpCodes.Ldelem_Ref)) { count++; } else if (ins.OpCode.Equals(OpCodes.Ldstr)) { count++; list.Add(ins.Operand as string); } } list.Reverse(); item.ModifyTooltips.AddRange(list); } } } method = type.FindMethod("UpdateArmorSet"); if (method?.HasBody == true) { var inst = method.Body.Instructions; for (var index = 0; index < inst.Count; index++) { var ins = inst[index]; if (ins.OpCode != OpCodes.Ldstr) { continue; } var value = ins.Operand as string; if ((ins = inst[++index]).OpCode == OpCodes.Stfld && ins.Operand is MemberRef m) { switch (m.Name) { case "setBonus": item.SetBonus = value; break; } } } } items.Add(item); } WriteFiles(items, DefaultConfigurations.LocalizerFiles.ItemFolder); }
private void DumpItems() { List <ItemTranslation> itemTranslations = new List <ItemTranslation>(); var itemTypes = from t in module.Types where t.HasBaseType("Terraria.ModLoader.ModItem") select t; foreach (var itemType in itemTypes) { ItemTranslation translation = new ItemTranslation { Namespace = itemType.Namespace, TypeName = itemType.Name }; // Name and Description MethodDef methodDef = itemType.FindMethod("SetStaticDefaults", MethodSig.CreateInstance(module.CorLibTypes.Void)); if (methodDef != null && methodDef.HasBody) { var instructions = methodDef.Body.Instructions; for (int i = 0; i < instructions.Count; i++) { Instruction cur = instructions[i]; if (cur.OpCode == OpCodes.Ldstr) { string val = cur.Operand as string; i++; cur = instructions[i]; IMethodDefOrRef m; if ((m = cur.Operand as IMethodDefOrRef) != null && m.Name == "SetDefault" && m.DeclaringType.Name == "ModTranslation") { cur = instructions[i - 2]; if (!(cur?.Operand is IMethodDefOrRef mdr)) { // some translation objects may get from stack; // In this case, we can't know their type. skip continue; } switch (mdr.Name) { case "get_Tooltip": translation.ToolTip = val; break; case "get_DisplayName": translation.Name = val; break; } } } } } // End Name and Description // Tooltips methodDef = itemType.FindMethod("ModifyTooltips"); if (methodDef != null && methodDef.HasBody) { var instructions = methodDef.Body.Instructions; for (int i = 0; i < instructions.Count; i++) { Instruction ins = instructions[i]; if (ins.OpCode != OpCodes.Newobj || !(ins.Operand is MemberRef memberRef) || !(memberRef.DeclaringType.Name == "TooltipLine")) { continue; } ins = instructions[i - 1]; if (ins.OpCode == OpCodes.Ldstr && instructions[i - 2].OpCode.Equals(OpCodes.Ldstr)) { translation.ModifyTooltips.Add(instructions[i - 2].Operand as string); translation.ModifyTooltips.Add(instructions[i - 1].Operand as string); } else if (ins.OpCode == OpCodes.Call && ins.Operand is MemberRef m && m.Name == "Concat") { } } } } }