public override void OnTrigger(FieldInstance instance) { base.OnTrigger(instance); parentFsm.Event("BossAlert"); PlaySound(61); }
public override void OnCollision(FieldInstance instance) { base.OnCollision(instance); IActionHandler target = Colliders[0] as IActionHandler; if (action is ActionSingle) { ActionSingle actionSingle = action as ActionSingle; if (target.IsActionApplicable(actionSingle.Type)) { var result = target.ApplyAction(actionSingle, this); if (result != null && result.value != 0) { OnHit(instance); } } } else { Debug.LogError("not implemented"); } //Remove(); RemoveOverlapEvent(); }
public override void OnTrigger(FieldInstance instance) { base.OnTrigger(instance); (instance as HeroCharacter).TryAddItem(item); Remove(); }
public override void OnTrigger(FieldInstance instance) { base.OnTrigger(instance); if (instance is HeroCharacter) { RemoveFromLayer(); EmitEvent("StageCleared"); } }
public override void OnTrigger(FieldInstance instance) { base.OnTrigger(instance); Action action = ActionPattern.Generate(actionPattern, Stat); if (action != null) { if (Fire(action, null)) { FSMEvent("OnTrigger"); } } }
public void AddChild(FieldInstance parent, FieldInstance child, float initX, float initY) { if (parent.Rect == null) { Debug.LogError("parent " + parent + " is not in layer"); } parent.Rect.point.layer.AddSubject(child, initX, initY); AddFieldInstance(child); }
void MoveToAfterNext(FieldInstance entity, LinkedListNode<FieldInstance> next) { LinkedListNode<FieldInstance> current = fieldList.Find(entity); fieldList.Remove(current); fieldList.AddAfter(next, entity); }
public override void GetStatic(FieldInstance field) { throw new NotImplementedException(); }
void AddFieldInstance(FieldInstance instance) { instance.SetField(this); if (fieldList.First == null || instance.Position < fieldList.First.Value.Position) { fieldList.AddFirst(instance); } else if (fieldList.Last.Value.Position <= instance.Position) { fieldList.AddLast(instance); } else { foreach (var entity in fieldList) { LinkedListNode<FieldInstance> current = fieldList.Find(entity); if (current.Value.Position <= instance.Position && instance.Position < current.Next.Value.Position) { fieldList.AddAfter(current, instance); break; } } } }
private object GetParsedValue(FieldInstance fieldInstanceType, object value) { ParseFieldValueAction action = LDtkFieldParser.GetParserMethodForType(fieldInstanceType); return(action?.Invoke(value)); }
public override void PutField(FieldInstance field) { throw new NotImplementedException(); }
public override FieldInstance ImplementField(FieldInstance field, FScript script) { return(base.ImplementField(field, script)); }
protected override void OnHit(FieldInstance instance) { base.OnHit(instance); if (objectProjectile.ImpactSFX > 0) { instance.PlaySound(objectProjectile.ImpactSFX); } }
public override IFieldVisitor VisitField(FieldInstance field) { return(new TraceFieldVisitor(base.VisitField(field), sb)); }
public override FieldInstance ImplementField(FieldInstance field) { return(base.ImplementField(field)); }
public override FieldInstance HideFromDebug(FieldInstance field) { return(base.HideFromDebug(field)); }
public override PropertyInstance ImplementGetter(PropertyInstance property, FieldInstance field) { return(base.ImplementGetter(property, field)); }
public override MethodInstance ImplementGetter(MethodInstance method, FieldInstance field) { return(base.ImplementGetter(method, field)); }
public VectorControl(FieldInstance mover) { this.mover = mover; }
bool ILDtkValueParser.TypeName(FieldInstance instance) { return(instance.IsString); }
public override void OnCollision(FieldInstance instance) { base.OnCollision(instance); FSMEvent("OnCollision"); }
/// ------------------------------------------------------------------------------------ public virtual IEnumerable <string> GetAllParticipants() { var allParticipants = MetaDataFile.GetStringValue(SessionFileType.kParticipantsFieldName, string.Empty); return(FieldInstance.GetMultipleValuesFromText(allParticipants)); }
public override void VisitEnd() { HashMap <String, List <MethodInfo> > nameToMethodsMap = new HashMap <String, List <MethodInfo> >(); foreach (MethodInfo method in ReflectUtil.GetMethods(State.OriginalType)) { List <MethodInfo> methodList = nameToMethodsMap.Get(method.Name); if (methodList == null) { methodList = new List <MethodInfo>(); nameToMethodsMap.Put(method.Name, methodList); } methodList.Add(method); } foreach (IPropertyInfo propertyInfo in propertyInfos) { MethodInfo getter = ((MethodPropertyInfo)propertyInfo).Getter; MethodInfo setter = ((MethodPropertyInfo)propertyInfo).Setter; if (getter == null) { // look for abstract definition of the getter getter = ReflectUtil.GetDeclaredMethod(true, State.CurrentType, propertyInfo.PropertyType, "get_" + propertyInfo.Name); } if (setter == null) { // look for abstract definition of the setter setter = ReflectUtil.GetDeclaredMethod(true, State.CurrentType, typeof(void), "set_" + propertyInfo.Name, propertyInfo.PropertyType); } MethodInstance m_getterTemplate = getter != null ? new MethodInstance(getter) : null; MethodInstance m_setterTemplate = setter != null ? new MethodInstance(setter) : null; MethodInstance m_getter = MethodInstance.FindByTemplate(m_getterTemplate, true); MethodInstance m_setter = MethodInstance.FindByTemplate(m_setterTemplate, true); if (m_getter != null && m_setter != null) { // ensure both accessors are public if (!m_getter.Access.HasFlag(MethodAttributes.Public)) { IMethodVisitor mv = VisitMethod(m_getter.DeriveAccess(MethodAttributes.Public)); mv.LoadThis(); mv.LoadArgs(); mv.InvokeSuper(m_getter); mv.ReturnValue(); mv.EndMethod(); } if (!m_setter.Access.HasFlag(MethodAttributes.Public)) { IMethodVisitor mv = VisitMethod(m_setter.DeriveAccess(MethodAttributes.Public)); mv.LoadThis(); mv.LoadArgs(); mv.InvokeSuper(m_getter); mv.ReturnValue(); mv.EndMethod(); } continue; } if (m_getter != null || m_setter != null) { // at least one of the accessors is explicitly implemented continue; } FieldInstance f_backingField = EnsureBackingField(propertyInfo); if (f_backingField == null) { continue; } if (m_setterTemplate == null) { m_setterTemplate = new MethodInstance(null, MethodAttributes.Public | MethodAttributes.SpecialName, m_setterTemplate != null ? m_setterTemplate.ReturnType : NewType.VOID_TYPE, "set_" + propertyInfo.Name, f_backingField.Type); } // implement setter m_setterTemplate = ImplementSetter(m_setterTemplate, f_backingField); List <MethodInfo> allSettersWithSameName = nameToMethodsMap.Get(m_setterTemplate.Name); if (allSettersWithSameName != null) { MethodInstance f_m_setterTemplate = m_setterTemplate; foreach (MethodInfo setterWithSameName in allSettersWithSameName) { MethodInstance m_setterWithSameName = MethodInstance.FindByTemplate(setterWithSameName, true); if (m_setterWithSameName != null) { // method is implemented, so nothing to do continue; } IMethodVisitor mv = VisitMethod(new MethodInstance(setterWithSameName)); if (mv.Method.Parameters.Length != 1) { // this visitor handles only "true" setters with exactly one argument continue; } mv.CallThisSetter(m_setterTemplate, delegate(IMethodVisitor mg) { mg.LoadArg(0); mg.CheckCast(f_m_setterTemplate.Parameters[0].Type); }); mv.ReturnVoidOrThis(); mv.EndMethod(); } } if (m_getterTemplate == null) { m_getterTemplate = new MethodInstance(null, MethodAttributes.Public | MethodAttributes.SpecialName, f_backingField.Type, "get_" + propertyInfo.Name, null); } // implement getter m_getterTemplate = ImplementGetter(m_getterTemplate, f_backingField); List <MethodInfo> allGettersWithSameName = nameToMethodsMap.Get(m_getterTemplate.Name); if (allGettersWithSameName != null) { foreach (MethodInfo getterWithSameName in allGettersWithSameName) { MethodInstance m_getterWithSameName = MethodInstance.FindByTemplate(getterWithSameName, true); if (m_getterWithSameName != null) { // method is implemented, so nothing to do continue; } IMethodVisitor mv = VisitMethod(new MethodInstance(getterWithSameName)); mv.CallThisGetter(m_getterTemplate); mv.ReturnValue(); mv.EndMethod(); } } } base.VisitEnd(); }
protected void ImplementSetPrimitives(Member[] primitiveMembers, FieldInstance[] f_primitives, FieldInstance[] f_nullFlags) { MethodInstance template_m_setPrimitives = new MethodInstance(null, typeof(RootCacheValue), typeof(void), "SetPrimitives", typeof(Object[])); IMethodVisitor mv = VisitMethod(template_m_setPrimitives); LocalVariableInfo loc_item = mv.NewLocal(objType); for (int primitiveIndex = 0, size = f_primitives.Length; primitiveIndex < size; primitiveIndex++) { FieldInstance f_primitive = f_primitives[primitiveIndex]; FieldInstance f_nullFlag = f_nullFlags[primitiveIndex]; Member member = primitiveMembers[primitiveIndex]; Type originalType = member.RealType; Script script_loadArrayValue = new Script(delegate(IMethodVisitor mg) { mg.LoadArg(0); mg.Push(primitiveIndex); mg.ArrayLoad(objType); }); Label l_finish = mv.NewLabel(); if (f_nullFlag == null) { if (!originalType.IsValueType) { mv.PutThisField(f_primitive, script_loadArrayValue); continue; } script_loadArrayValue(mv); mv.StoreLocal(loc_item); mv.LoadLocal(loc_item); mv.IfNull(l_finish); mv.PutThisField(f_primitive, new Script(delegate(IMethodVisitor mg) { mg.LoadLocal(loc_item); mg.Unbox(f_primitive.Type.Type); })); mv.Mark(l_finish); continue; } Label l_itemIsNull = mv.NewLabel(); script_loadArrayValue(mv); mv.StoreLocal(loc_item); mv.LoadLocal(loc_item); mv.IfNull(l_itemIsNull); mv.PutThisField(f_primitive, delegate(IMethodVisitor mg) { mg.LoadLocal(loc_item); mg.Unbox(f_primitive.Type.Type); }); if (f_nullFlag != null) { // field is a nullable numeric value in the entity, but a native numeric value in our RCV mv.PutThisField(f_nullFlag, delegate(IMethodVisitor mg) { mg.Push(false); }); } mv.GoTo(l_finish); mv.Mark(l_itemIsNull); if (f_nullFlag != null) { // field is a nullable numeric value in the entity, but a native numeric value in our RCV mv.PutThisField(f_nullFlag, delegate(IMethodVisitor mg) { mg.Push(true); }); } else { mv.PutThisField(f_primitive, delegate(IMethodVisitor mg) { mg.PushNullOrZero(f_primitive.Type.Type); }); } mv.Mark(l_finish); } mv.ReturnValue(); mv.EndMethod(); }
private static void ParseCustomFields <T>(T classFields, FieldInstance[] fields, LDtkLevel level) { for (int i = 0; i < fields.Length; i++) { FieldInstance fieldInstance = fields[i]; string variableName = fieldInstance._Identifier; PropertyInfo variableDef = typeof(T).GetProperty(variableName); if (variableDef == null) { throw new FieldNotFoundException($"Error: Field \"{variableName}\" not found in {typeof(T).FullName}. Maybe you should run ldtkgen again to update the files?"); } // Split any enums int enumTypeIndex = fieldInstance._Type.LastIndexOf('.'); int arrayEndIndex = fieldInstance._Type.LastIndexOf('>'); string variableType = fieldInstance._Type; if (enumTypeIndex != -1) { variableType = arrayEndIndex != -1 ? variableType.Remove(enumTypeIndex, arrayEndIndex - enumTypeIndex) : variableType.Remove(enumTypeIndex, variableType.Length - enumTypeIndex); } switch (variableType) { case Field.IntType: case Field.BoolType: case Field.EnumType: case Field.FloatType: case Field.StringType: case Field.FilePathType: if (fieldInstance._Value != null) { variableDef.SetValue(classFields, Convert.ChangeType(fieldInstance._Value.ToString(), variableDef.PropertyType)); } break; case Field.IntArrayType: case Field.BoolArrayType: case Field.EnumArrayType: case Field.FloatArrayType: case Field.StringArrayType: case Field.FilePathArrayType: case Field.LocalEnumArrayType: object primativeArrayValues = JsonSerializer.Deserialize(fieldInstance._Value.ToString(), variableDef.PropertyType, new JsonSerializerOptions() { Converters = { new JsonStringEnumConverter() } }); variableDef.SetValue(classFields, Convert.ChangeType(primativeArrayValues, variableDef.PropertyType)); break; case Field.LocalEnumType: variableDef.SetValue(classFields, Enum.Parse(variableDef.PropertyType, fieldInstance._Value.ToString())); break; case Field.ColorType: variableDef.SetValue(classFields, ParseStringToColor(fieldInstance._Value.ToString())); break; // Only Entities can have point fields case Field.PointType: if (fieldInstance._Value != null) { if (variableDef.PropertyType == typeof(Vector2)) { Vector2 vector = (Vector2)fieldInstance._Value; variableDef.SetValue(classFields, vector); } else if (variableDef.PropertyType == typeof(Point)) { Point point = JsonSerializer.Deserialize <Point>(fieldInstance._Value.ToString(), new JsonSerializerOptions() { Converters = { new CxCyConverter() } }); variableDef.SetValue(classFields, point); } } else { if (variableDef.PropertyType == typeof(Vector2)) { variableDef.SetValue(classFields, Vector2.Zero); } else if (variableDef.PropertyType == typeof(Point)) { variableDef.SetValue(classFields, Point.Zero); } } break; case Field.PointArrayType: List <Point> points = JsonSerializer.Deserialize <List <Point> >(fieldInstance._Value.ToString(), new JsonSerializerOptions() { Converters = { new CxCyConverter() } }); int gridSize = 0; for (int j = 0; j < level.LayerInstances.Length; j++) { if (level.LayerInstances[j]._Type == LayerType.Entities) { gridSize = level.LayerInstances[j]._GridSize; } } for (int j = 0; j < points.Count; j++) { points[j] = new Point(points[j].X * gridSize, points[j].Y * gridSize); points[j] += level.Position; points[j] += new Point(gridSize / 2); } variableDef.SetValue(classFields, points.ToArray()); break; default: throw new FieldNotFoundException("Unknown Variable of type " + fieldInstance._Type); } } }
protected void ImplementPropertyChangeOnProperty(PropertyInstance propertyInfo, PropertyInstance p_propertyChangeTemplate, MethodInstance m_firePropertyChange, FieldInstance f_propertyChangeSupport) { // add property change detection and notification if (propertyInfo.Getter == null || propertyInfo.Setter == null) { return; } if (InitializeEmbeddedMemberVisitor.IsEmbeddedMember(metaData, propertyInfo.Name)) { return; } PropertyInstance p_getterMethodHandle = ImplementAssignedReadonlyProperty(propertyInfo.Name + "$MethodHandle", new MethodHandleValueResolver(PropertyInfoProvider, propertyInfo.Name)); Type propertyType = propertyInfo.PropertyType.Type; MethodInstance m_hasPropertyChanged = GetApplicableHasPropertyChangedOverload(propertyType); // check value type of last parameter bool isBoxingNeededForHasPropertyChanged = IsBoxingNeededForHasPropertyChangedOverload(m_hasPropertyChanged, propertyType); IMethodVisitor mg = VisitMethod(propertyInfo.Setter); Label l_finish = mg.NewLabel(); Label l_noOldValue = mg.NewLabel(); Label l_noChangeCheck = mg.NewLabel(); LocalVariableInfo loc_oldValue; if (isBoxingNeededForHasPropertyChanged) { loc_oldValue = mg.NewLocal(typeof(Object)); } else { loc_oldValue = mg.NewLocal(propertyType); } LocalVariableInfo loc_valueChanged = mg.NewLocal <bool>(); MethodInstance m_getSuper = EnhancerUtil.GetSuperGetter(propertyInfo); bool relationProperty = m_getSuper.Name.EndsWith(ValueHolderIEC.GetNoInitSuffix()); // initialize flag with false mg.Push(false); mg.StoreLocal(loc_valueChanged); // initialize oldValue with null mg.PushNullOrZero(loc_oldValue.LocalType); mg.StoreLocal(loc_oldValue); if (relationProperty) { // check if a setter call to an UNINITIALIZED relation occured with value null // if it the case there would be no PCE because oldValue & newValue are both null // but we need a PCE in this special case Label l_noSpecialHandling = mg.NewLabel(); FieldInstance f_state = State.GetAlreadyImplementedField(ValueHolderIEC.GetInitializedFieldName(propertyInfo.Name)); mg.GetThisField(f_state); mg.PushEnum(ValueHolderState.INIT); mg.IfCmp(typeof(ValueHolderState), CompareOperator.EQ, l_noSpecialHandling); mg.Push(true); mg.StoreLocal(loc_valueChanged); mg.Mark(l_noSpecialHandling); } // check if value should be checked to decide for a PCE mg.LoadLocal(loc_valueChanged); mg.IfZCmp(CompareOperator.NE, l_noOldValue); // get old field value calling super property getter mg.LoadThis(); mg.InvokeOnExactOwner(m_getSuper); if (isBoxingNeededForHasPropertyChanged) { mg.Box(propertyType); } mg.StoreLocal(loc_oldValue); mg.Mark(l_noOldValue); // set new field value calling super property setter mg.LoadThis(); mg.LoadArg(0); mg.InvokeOnExactOwner(EnhancerUtil.GetSuperSetter(propertyInfo)); mg.PopIfReturnValue(EnhancerUtil.GetSuperSetter(propertyInfo)); // check if value should be checked to decide for a PCE mg.LoadLocal(loc_valueChanged); mg.IfZCmp(CompareOperator.NE, l_noChangeCheck); LocalVariableInfo loc_newValue = null; if (isBoxingNeededForHasPropertyChanged) { loc_newValue = mg.NewLocal(typeof(Object)); // loc_1 Object newValue // Object loc_1 = (Object)value; mg.LoadArg(0); mg.Box(propertyType); mg.StoreLocal(loc_newValue); } mg.CallThisGetter(p_propertyChangeTemplate); // call HasPropertyChanged (static) mg.LoadThis(); // "this" as Object obj mg.Push(propertyInfo.Name); // String propertyName mg.LoadLocal(loc_oldValue); if (loc_newValue != null) { mg.LoadLocal(loc_newValue); } else { mg.LoadArg(0); } mg.InvokeVirtual(m_hasPropertyChanged); //// if (!result) //// { return; } mg.IfZCmp(CompareOperator.EQ, l_finish); mg.Mark(l_noChangeCheck); // call firePropertyChange on this mg.LoadThis(); // propertyChangeSupport mg.GetThisField(f_propertyChangeSupport); // property mg.CallThisGetter(p_getterMethodHandle); // oldValue mg.LoadLocal(loc_oldValue); if (!isBoxingNeededForHasPropertyChanged && propertyType.IsValueType) { // old value has not already been boxed but it is now necessary mg.ValueOf(propertyType); } // newValue if (loc_newValue != null) { mg.LoadLocal(loc_newValue); } else { mg.LoadArg(0); if (propertyType.IsValueType) { mg.ValueOf(propertyType); } } // firePropertyChange(propertyChangeSupport, property, oldValue, newValue) mg.InvokeVirtual(m_firePropertyChange); // return mg.Mark(l_finish); mg.ReturnVoidOrThis(); mg.EndMethod(); }
public override void PutThisField(FieldInstance field, Script script) { throw new NotImplementedException(); }
protected MethodInstance ImplementUsePropertyChangeSupport(PropertyInstance p_propertyChangeTemplate, FieldInstance f_propertyChangeSupport) { MethodInstance m_getPropertyChangeSupport = MethodInstance.FindByTemplate(template_m_usePropertyChangeSupport, true); if (m_getPropertyChangeSupport == null) { // create field that holds propertyChangeSupport f_propertyChangeSupport = ImplementField(f_propertyChangeSupport); IMethodVisitor mg = VisitMethod(template_m_usePropertyChangeSupport); HideFromDebug(mg.Method); Label l_pcsValid = mg.NewLabel(); mg.GetThisField(f_propertyChangeSupport); mg.Dup(); mg.IfNonNull(l_pcsValid); mg.Pop(); // remove 2nd null instance from stack caused by previous dup mg.PutThisField(f_propertyChangeSupport, delegate(IMethodVisitor mg2) { mg.CallThisGetter(p_propertyChangeTemplate); mg.LoadThis(); mg.InvokeVirtual(m_newPropertyChangeSupport); }); mg.GetThisField(f_propertyChangeSupport); mg.Mark(l_pcsValid); mg.ReturnValue(); // return instance already on the stack by both branches mg.EndMethod(); m_getPropertyChangeSupport = mg.Method; } return(m_getPropertyChangeSupport); }
bool ILDtkValueParser.TypeName(FieldInstance instance) => instance.IsBool;
protected PropertyInstance ImplementNotifyPropertyChangedSource(PropertyInstance p_propertyChangeTemplate, FieldInstance f_propertyChangeSupport) { MethodInstance m_onPropertyChanged_Values = MethodInstance.FindByTemplate(template_m_onPropertyChanged_Values, true); if (m_onPropertyChanged_Values == null) { IMethodVisitor mv = VisitMethod(template_m_onPropertyChanged_Values); mv.CallThisGetter(p_propertyChangeTemplate); mv.LoadThis(); mv.GetThisField(f_propertyChangeSupport); // getMethodHandle(sender, propertyName) mv.CallThisGetter(p_propertyChangeTemplate); mv.LoadThis(); mv.LoadArg(0); mv.InvokeVirtual(m_getMethodHandle); mv.LoadArg(1); mv.LoadArg(2); // firePropertyChange(sender, propertyChangeSupport, property, oldValue, newValue) mv.InvokeVirtual(m_firePropertyChange); mv.PopIfReturnValue(m_firePropertyChange); mv.ReturnVoidOrThis(); mv.EndMethod(); m_onPropertyChanged_Values = mv.Method; } MethodInstance m_onPropertyChanged = MethodInstance.FindByTemplate(template_m_onPropertyChanged, true); if (m_onPropertyChanged == null) { IMethodVisitor mv = VisitMethod(template_m_onPropertyChanged); mv.LoadThis(); mv.LoadArg(0); mv.PushNull(); mv.PushNull(); mv.InvokeVirtual(m_onPropertyChanged_Values); mv.PopIfReturnValue(m_onPropertyChanged_Values); mv.ReturnVoidOrThis(); mv.EndMethod(); m_onPropertyChanged = mv.Method; } PropertyInstance p_pceHandlers = PropertyInstance.FindByTemplate(p_propertyChangeSupport, true); if (p_pceHandlers == null) { HideFromDebug(ImplementGetter(p_propertyChangeSupport.Getter, f_propertyChangeSupport)); p_pceHandlers = PropertyInstance.FindByTemplate(p_propertyChangeSupport, false); } if (EmbeddedEnhancementHint.HasMemberPath(State.Context)) { PropertyInstance p_parentEntity = EmbeddedTypeVisitor.GetParentObjectProperty(this); if (MethodInstance.FindByTemplate(p_parentChildEventHandler.Getter, true) == null) { IMethodVisitor mv = VisitMethod(p_parentChildEventHandler.Getter); mv.CallThisGetter(p_parentEntity); mv.InvokeInterface(p_parentChildEventHandler.Getter); mv.ReturnValue(); mv.EndMethod(); HideFromDebug(mv.Method); } if (MethodInstance.FindByTemplate(p_collectionEventHandler.Getter, true) == null) { IMethodVisitor mv = VisitMethod(p_collectionEventHandler.Getter); mv.CallThisGetter(p_parentEntity); mv.InvokeInterface(p_collectionEventHandler.Getter); mv.ReturnValue(); mv.EndMethod(); HideFromDebug(mv.Method); } } else { if (MethodInstance.FindByTemplate(p_parentChildEventHandler.Getter, true) == null) { HideFromDebug(ImplementLazyInitProperty(p_parentChildEventHandler, delegate(IMethodVisitor mv) { MethodInstance method = new MethodInstance(null, typeof(NotifyPropertyChangedClassVisitor), typeof(PropertyChangedEventHandler), "CreateParentChildEventHandler", typeof(Object)); mv.LoadThis(); mv.InvokeStatic(method); })); } if (MethodInstance.FindByTemplate(p_collectionEventHandler.Getter, true) == null) { HideFromDebug(ImplementLazyInitProperty(p_collectionEventHandler, delegate(IMethodVisitor mv) { MethodInstance method = new MethodInstance(null, typeof(NotifyPropertyChangedClassVisitor), typeof(NotifyCollectionChangedEventHandler), "CreateCollectionEventHandler", typeof(Object)); mv.LoadThis(); mv.InvokeStatic(method); })); } } //MethodAttributes ma = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig; //{ // ConstructorInfo pceaCI = typeof(PropertyChangedEventArgs).GetConstructor(new Type[] { typeof(String) }); // MethodBuilder mb = VisitorUtil.DefineMethod(vs, onPropertyChangedMI_string, ma); // ILGenerator gen = mb.GetILGenerator(); // gen.Emit(OpCodes.Ldarg_0); // gen.Emit(OpCodes.Ldarg_1); // gen.Emit(OpCodes.Newobj, pceaCI); // gen.Emit(OpCodes.Call, onPropertyChangedMI_pceArg); // gen.Emit(OpCodes.Ret); //} //{ // MethodBuilder mb = VisitorUtil.DefineMethod(vs, onPropertyChangedMI_pceArg, ma); // ILGenerator gen = mb.GetILGenerator(); // gen.Emit(OpCodes.Ldarg_0); // gen.Emit(OpCodes.Call, pctPI.GetGetMethod()); // gen.Emit(OpCodes.Ldarg_0); // gen.Emit(OpCodes.Ldarg_1); // gen.Emit(OpCodes.Call, FirePropertyChangedMI); // gen.Emit(OpCodes.Ret); //} // List<PropertyChangedEventHandler> PropertyChangedEventHandlers { get; } //void OnPropertyChanged(String propertyName); //void OnPropertyChanged(PropertyChangedEventArgs args); return(p_pceHandlers); }
public void RemoveInstance(FieldInstance instance) { removeTemp.Add(instance); instance.RemoveOverlapEvent(); }
public FieldInstance FindForward(FieldInstance self, E_OverlapEvent overlapEvent) { SearchCondition condition = delegate(FieldInstance sample, ref bool stopSearch) { if (sample.ToLeft != self.ToLeft) { if (sample.overlapEvent == overlapEvent) { return true; } } return false; }; return Find(self, condition, self.ToLeft); }
private static void AdjustContactLine(FieldInstance[] conflicts) { List<FieldInstance> paused = new List<FieldInstance>(); List<FieldInstance> stopped = new List<FieldInstance>(); foreach (var entity in conflicts) { if (entity.IsMovementStopped()) { stopped.Add(entity); } else if (entity.IsMovementPaused() && !(entity is Projectile)) { paused.Add(entity); } } if (paused.Count == 0) { // do nothing return; } else if (paused.Count == 1 && stopped.Count == 1) { paused[0].Move(new Vector2(stopped[0].PosX - paused[0].PosX, 0)); } else if (paused.Count == 2) { Debug.LogError("not implemented"); } }
IEnumerable<FieldInstance> FindAll(FieldInstance start, SearchCondition condition, bool toLeft) { List<FieldInstance> ret = new List<FieldInstance>(); LinkedListNode<FieldInstance> curr = fieldList.Find(start); while (curr != null) { bool stopSearch = false; if (condition(curr.Value, ref stopSearch)) { ret.Add(curr.Value); } if (stopSearch) { break; } curr = toLeft ? curr.Previous : curr.Next; } return ret; }
public IEnumerable<FieldInstance> FindContacts(FieldInstance self, E_OverlapEvent overlapEvent) { SearchCondition condition = delegate(FieldInstance sample, ref bool stopSearch) { if (sample.PosX == self.PosX) { if (sample.ToLeft != self.ToLeft) { if (sample.overlapEvent == overlapEvent) { return true; } } } else { stopSearch = true; } return false; }; List<FieldInstance> ret = new List<FieldInstance>(); ret.AddRange(FindAll(self, condition, true)); ret.AddRange(FindAll(self, condition, false)); return ret; }
public override void OnCollisionDisappear(FieldInstance instance) { base.OnCollisionDisappear(instance); FSMEvent("OnCollisionDisappear"); }
FieldInstance Find(FieldInstance start, SearchCondition condition, bool toLeft) { LinkedListNode<FieldInstance> curr = fieldList.Find(start); while (curr != null) { bool stopSearch = false; if (condition(curr.Value, ref stopSearch)) { return curr.Value; } if (stopSearch) { break; } curr = toLeft ? curr.Previous : curr.Next; } return null; }
public FieldItem(FieldInstance parent, ItemCommand item) : base(E_OverlapEvent.Trigger, 1, 1, WorldAnchor.BottomLeft) { this.item = item; }
public FieldWrapper(FieldInstance baseInstance) : base(baseInstance.Info) { BaseInstance = baseInstance; }
protected virtual void OnHit(FieldInstance instance) { }
public override void OnCollision(FieldInstance instance) { base.OnCollision(instance); if (!isBattleStarted) { if (objectMonster.MonsterReactType == E_MonsterReactType.Hostile) { StartBattle(); } } }
protected void ImplementRelationGetter(String propertyName, MethodInstance m_getMethod_template, MethodInstance m_setMethod, int relationIndex, PropertyInstance p_valueHolderContainerTemplate, PropertyInstance p_targetCache, PropertyInstance p_relationMembers, FieldInstance f_initialized, FieldInstance f_objRefs) { // public String getPropertyName() // { // if (!PropertyName$initialized) // { // setPropertyName(RelationsGetterVisitor.valueHolderContainer_getValue(this, $relationMembers, get__IndexOfPropertyName(), $targetCache, $beanContext, // propertyName$objRefs)); // } // return super.getPropertyName(); // } Script script_getVHC; if (EmbeddedEnhancementHint.HasMemberPath(State.Context)) { PropertyInstance p_rootEntity = EmbeddedTypeVisitor.GetRootEntityProperty(this); script_getVHC = delegate(IMethodVisitor mv) { mv.CallThisGetter(p_rootEntity); }; } else { script_getVHC = delegate(IMethodVisitor mv) { // this mv.LoadThis(); }; } MethodInstance m_getMethod; { PropertyInstance p_cacheModification = SetCacheModificationMethodCreator.GetCacheModificationPI(this); MethodInstance m_getMethod_scoped = new MethodInstance(State.NewType, MethodAttributes.HideBySig | MethodAttributes.Private | MethodAttributes.Final, NewType.VOID_TYPE, propertyName + "$DoInitialize"); { IMethodVisitor mg = VisitMethod(m_getMethod_scoped); // this => for this.setPropertyName(...) mg.LoadThis(); // call template.getValue(..) mg.CallThisGetter(p_valueHolderContainerTemplate); // getVhc() script_getVHC.Invoke(mg); // $relationMembers mg.CallThisGetter(p_relationMembers); // get__IndexOfPropertyName() mg.Push(relationIndex); // $targetCache mg.CallThisGetter(p_targetCache); // propertyName$objRefs mg.GetThisField(f_objRefs); mg.InvokeVirtual(m_template_getValue); mg.CheckCast(m_setMethod.Parameters[0].Type); mg.InvokeVirtual(m_setMethod); mg.ReturnValue(); mg.EndMethod(); } { IMethodVisitor mg = base.VisitMethod(m_getMethod_template); m_getMethod = mg.Method; HideFromDebug(m_getMethod); Label l_initialized = mg.NewLabel(); mg.GetThisField(f_initialized); mg.PushEnum(ValueHolderState.INIT); mg.IfCmp(typeof(ValueHolderState), CompareOperator.EQ, l_initialized); SetCacheModificationMethodCreator.CacheModificationInternalUpdate(p_cacheModification, mg, delegate(IMethodVisitor mv2) { mv2.LoadThis(); mv2.InvokeOnExactOwner(m_getMethod_scoped); }); mg.Mark(l_initialized); mg.LoadThis(); mg.InvokeSuperOfCurrentMethod(); mg.ReturnValue(); mg.EndMethod(); } } // public String getPropertyName$NoInit() // { // return super.getPropertyName(); // } { MethodInstance m_getNoInit = m_getMethod_template.DeriveName(ValueHolderIEC.GetGetterNameOfRelationPropertyWithNoInit(propertyName)); IMethodVisitor mg = base.VisitMethod(m_getNoInit); PropertyInstance p_getNoInit = PropertyInstance.FindByTemplate(propertyName + ValueHolderIEC.GetNoInitSuffix(), m_getNoInit.ReturnType, false); p_getNoInit.AddAnnotation(c_fireThisOPC, propertyName); p_getNoInit.AddAnnotation(c_fireTargetOPC, propertyName); mg.LoadThis(); mg.InvokeSuper(m_getMethod); mg.ReturnValue(); mg.EndMethod(); } }
public override void OnCollision(FieldInstance instance) { base.OnCollision(instance); if (objectProjectile.ExplosionVFX > 0) { Vector2 offset = Rect.point - instance.Rect.point; if (instance.ToLeft) { offset.x -= instance.Rect.width / 2; } else { offset.x += instance.Rect.width / 2; } offset.y += Rect.height / 2; Vector3 offset3d = offset; offset3d.z = -0.5f; ResourceVFX effect = TableLoader.GetTable<ResourceVFX>().Get(objectProjectile.ExplosionVFX); GameObject child = RecycleManager.Instance.Instantiate(effect.Resource); instance.AttachChild(child, "BC", offset3d); } if (objectProjectile.ImpactType == E_ImpactType.Destroy) { Remove(); } else { float speedX = Mathf.Abs(Velocity.x); float velY = Velocity.y; float speedReductionRatio = Random.Range(objectProjectile.MinimumSpeedReduction, objectProjectile.MaximumSpeedReduction); float bounceSpeedRatio = Mathf.Max(0, 1 - speedReductionRatio); var movement = VectorGenerator.Custom(speedX * bounceSpeedRatio, velY * bounceSpeedRatio, objectProjectile.FallingGravity, !ToLeft); if (!instance.IsMovementPaused()) { Vector2 targetVel = instance.Velocity; if (targetVel != Vector2.zero) { movement.Add(new LinearVelocity(targetVel)); } } SetMove(movement); ChangeMotion("bounce"); } }
protected void ImplementRelationSetter(String propertyName, MethodInstance m_set_template, FieldInstance f_initialized, FieldInstance f_objRefs) { // public void setPropertyName(String propertyName) // { // PropertyName$initialized = true; // PropertyName$objRefs = null; // super.setPropertyName(propertyName); // } MethodInstance m_set; { IMethodVisitor mg = base.VisitMethod(m_set_template); m_set = mg.Method; mg.PutThisField(f_initialized, delegate(IMethodVisitor mv2) { mg.PushEnum(ValueHolderState.INIT); }); mg.PutThisField(f_objRefs, delegate(IMethodVisitor mv2) { mv2.PushNull(); }); mg.LoadThis(); mg.LoadArgs(); mg.InvokeSuperOfCurrentMethod(); mg.ReturnVoidOrThis(); mg.EndMethod(); } // public void setPropertyName$NoInit(String propertyName) // { // super.setPropertyName(propertyName); // } { String noInitSetMethodName = ValueHolderIEC.GetSetterNameOfRelationPropertyWithNoInit(propertyName); IMethodVisitor mv = base.VisitMethod(m_set.Access, noInitSetMethodName, m_set.ReturnType, m_set.Parameters); mv.LoadThis(); mv.LoadArgs(); mv.InvokeSuper(m_set); mv.ReturnVoidOrThis(); mv.EndMethod(); } }
private object GetSingle(FieldInstance fieldInstance) { return(GetParsedValue(fieldInstance, fieldInstance.Value)); }
protected void ImplementConstructors() { if (metaData.RelationMembers.Length == 0) { return; } RelationMember[] relationMembers = metaData.RelationMembers; List <FieldInstance[]> fieldsList = new List <FieldInstance[]>(); for (int a = relationMembers.Length; a-- > 0;) { RelationMember relationMember = relationMembers[a]; relationMember = (RelationMember)GetApplicableMember(relationMember); if (relationMember == null) { // member is handled in another type continue; } String propertyName = relationMember.Name; String fieldName = ValueHolderIEC.GetObjRefsFieldName(propertyName); FieldInstance field = State.GetAlreadyImplementedField(fieldName); String fieldName2 = ValueHolderIEC.GetInitializedFieldName(propertyName); FieldInstance field2 = State.GetAlreadyImplementedField(fieldName2); fieldsList.Add(new FieldInstance[] { field, field2 }); } if (fieldsList.Count == 0) { return; } PropertyInstance p_emptyRelations = ImplementAssignedReadonlyProperty("EmptyRelations", ObjRef.EMPTY_ARRAY); OverrideConstructors(delegate(IClassVisitor cv, ConstructorInstance superConstructor) { IMethodVisitor mv = cv.VisitMethod(superConstructor); mv.LoadThis(); mv.LoadArgs(); mv.InvokeSuperOfCurrentMethod(); LocalVariableInfo loc_emptyRelations = mv.NewLocal <IObjRef[]>(); LocalVariableInfo loc_lazyState = mv.NewLocal <ValueHolderState>(); mv.CallThisGetter(p_emptyRelations); mv.StoreLocal(loc_emptyRelations); mv.PushEnum(ValueHolderState.LAZY); mv.StoreLocal(loc_lazyState); foreach (FieldInstance[] fields in fieldsList) { mv.PutThisField(fields[0], delegate(IMethodVisitor mv2) { mv2.LoadLocal(loc_emptyRelations); }); mv.PutThisField(fields[1], delegate(IMethodVisitor mv2) { mv2.LoadLocal(loc_lazyState); }); } mv.ReturnValue(); mv.EndMethod(); }); }