public override StoryVar GetMember(StoryVar member) { StoryVar val; if (TryGetMemberArray(member, out val)) { return(val); } var memberName = member.ToString().ToLower(); if (memberName == "length") { val = this.Length; } else { int index; if (HarloweUtils.TryPositionToIndex(memberName, Values.Count, out index)) { try { val = Values[index]; } catch (System.IndexOutOfRangeException) { throw new VarTypeMemberException(string.Format("The array doesn't have a {0} position.", memberName)); } } else { throw new VarTypeMemberException(string.Format("The array doesn't have a member called {0}.", memberName)); } } return(new StoryVar(val)); }
public override void SetMember(StoryVar member, StoryVar value) { var memberName = member.ToString().ToLower(); if (memberName == "length") { throw new VarTypeMemberException("'length' cannot be modified."); } EnsureNotPosition(memberName); throw new VarTypeMemberException(string.Format("The dataset doesn't have a member called {0}.", memberName)); }
public override StoryVar GetMember(StoryVar member) { var memberName = member.ToString().ToLower(); if (memberName == "length") { return(this.Length); } EnsureNotPosition(memberName); throw new VarTypeMemberException(string.Format("The dataset doesn't have a member called {0}.", memberName)); }
public override StoryVar GetMember(StoryVar member) { StoryVar val; if (TryGetMemberArray(member, out val)) { return(val); } var memberName = member.ToString(); if (!Dictionary.TryGetValue(memberName, out val)) { throw new VarTypeMemberException(string.Format("The datamap doesn't have an entry under the name '{0}'.", memberName)); } return(new StoryVar(val)); }
public override void RemoveMember(StoryVar member) { var memberName = member.ToString().ToLower(); if (memberName == "length") { throw new VarTypeMemberException("'length' cannot be modified."); } int index; if (HarloweUtils.TryPositionToIndex(memberName, Values.Count, out index)) { try { Values.RemoveAt(index); } catch (System.IndexOutOfRangeException) { throw new VarTypeMemberException(string.Format("The array doesn't have a {0} position.", memberName)); } } else { throw new VarTypeMemberException(string.Format("The array doesn't have a member called {0}.", memberName)); } }
public override void RemoveMember(StoryVar member) { var memberName = member.ToString(); Dictionary.Remove(memberName); }
public override void SetMember(StoryVar member, StoryVar value) { var memberName = member.ToString(); Dictionary[memberName] = value.Duplicate(); }
protected EmbedFragment enchant(StoryVar reference, HarloweEnchantCommand command, Func <IStoryThread> fragment) { bool isHookRef = reference.Value is HarloweHookRef; string str = isHookRef ? ((HarloweHookRef)reference.Value).HookName : reference.ToString(); List <HarloweEnchantment> enchantments = new List <HarloweEnchantment>(); HarloweEnchantment lastHookEnchantment = null; for (int i = 0; i < this.Output.Count; i++) { StoryOutput output = this.Output[i]; if (isHookRef) { // Check if matching hook found in the current group, otherwise skip if (!(output is StyleGroup)) { continue; } var group = output as StyleGroup; if (group.Style.Get <string>(HarloweStyleSettings.Hook) != str) { continue; } // Matching hook was found, but enchantment metadata is not up to date if (lastHookEnchantment == null || lastHookEnchantment.HookGroup != group) { lastHookEnchantment = new HarloweEnchantment() { ReferenceType = HarloweEnchantReferenceType.Hook, Command = command, HookGroup = group, Affected = new List <StoryOutput>() }; enchantments.Add(lastHookEnchantment); } // Add all outputs associated with this group i++; while (i < this.Output.Count && this.Output[i].BelongsToStyleGroup(group)) { lastHookEnchantment.Affected.Add(this.Output[i]); i++; } } else if (output is StoryText) { var occurences = new Regex(Regex.Escape(str)); if (occurences.IsMatch(output.Text)) { enchantments.Add(new HarloweEnchantment { ReferenceType = HarloweEnchantReferenceType.Text, Command = command, Affected = new List <StoryOutput>() { output }, Text = str, Occurences = occurences }); } } } return(new EmbedFragment(() => EnchantExecute(enchantments, fragment))); }