Exemple #1
0
    public override void _Ready()
    {
        bool _autostart = Autostart;

        Autostart = false;
        base._Ready();

        if (syncedRandomDelay || pickOne)
        {
            parent = GetParent <GDKnyttBaseObject>();
        }
        if (syncedRandomDelay)
        {
            firstDelay = parent.GDArea.Selector.GetRandomValue(parent, WaitTime);
        }
        if (pickOne && !manualRegister)
        {
            parent.GDArea.Selector.Register(parent);
        }

        if (_autostart)
        {
            RunTimer();
        }
    }
Exemple #2
0
    public bool IsObjectSelected(GDKnyttBaseObject obj, bool by_type = false)
    {
        var type = getKey(obj, by_type);

        // Reset might be called sooner than an object is disposed, or object may be not registered
        if (!IsOpen || !allObjects.ContainsKey(type) || !allObjects[type].Contains(obj))
        {
            return(false);
        }

        if (selections[type] == null)
        {
            counters[type]   = 0;
            selections[type] = GDKnyttDataStore.random.NextElement(allObjects[type]);
        }

        counters[type]++;
        bool is_selected = selections[type] == obj;

        if (counters[type] >= allObjects[type].Count)
        {
            counters[type]   = 0;
            selections[type] = GDKnyttDataStore.random.NextElement(allObjects[type]);
        }

        return(is_selected);
    }
Exemple #3
0
 public override void _Ready()
 {
     parent = GetParent <GDKnyttBaseObject>();
     if (!parent.Juni.Powers.getPower(YKnyttLib.JuniValues.PowerNames.Eye))
     {
         parent.QueueFree();
     }
 }
Exemple #4
0
    public float GetRandomValue(GDKnyttBaseObject obj, float maxValue, bool by_type = false)
    {
        var type = getKey(obj, by_type);

        if (!randomValues.ContainsKey(type))
        {
            randomValues.Add(type, GDKnyttDataStore.random.NextFloat(maxValue));
        }
        return(randomValues[type]);
    }
Exemple #5
0
    public int GetIndex(GDKnyttBaseObject obj, bool by_type = false)
    {
        var type = getKey(obj, by_type);

        if (!allObjects.ContainsKey(type))
        {
            return(0);
        }
        return(allObjects[type].IndexOf(obj));
    }
Exemple #6
0
    public void Unregister(GDKnyttBaseObject obj, bool by_type = false)
    {
        var type = getKey(obj, by_type);

        if (!allObjects.ContainsKey(type))
        {
            return;
        }
        allObjects[type].Remove(obj);
        counters[type]   = 0;
        selections[type] = null;
    }
Exemple #7
0
    // Do not call Register and Unregister in IsObjectSelected series!
    public void Register(GDKnyttBaseObject obj, bool by_type = false)
    {
        var type = getKey(obj, by_type);

        if (!allObjects.ContainsKey(type))
        {
            allObjects[type] = new List <object>();
            counters[type]   = 0;
            selections[type] = null;
        }
        allObjects[type].Add(obj);
    }
Exemple #8
0
    public override void _Ready()
    {
        Node candidate = GetParent();

        while (!(candidate is GDKnyttBaseObject))
        {
            candidate = candidate.GetParent();
        }
        parent = candidate as GDKnyttBaseObject;

        if (parent.Juni.Powers.getCollectable(parent.ObjectID.y))
        {
            parent.QueueFree();
            return;
        }
        var area = GetNode <Area2D>("Area2D");

        area.AddChild(GetNode <Node2D>(collisionPath).Duplicate());
    }
Exemple #9
0
 public override void _Ready()
 {
     parent     = GetParent <GDKnyttBaseObject>();
     globalJuni = parent.Juni;
     sprite     = spritePath != null?GetNode <AnimatedSprite>(spritePath) : null;
 }
Exemple #10
0
    public int GetSize(GDKnyttBaseObject obj, bool by_type = false)
    {
        var type = getKey(obj, by_type);

        return(allObjects.ContainsKey(type) ? allObjects[type].Count : 0);
    }
Exemple #11
0
 private object getKey(GDKnyttBaseObject obj, bool by_type)
 {
     return(by_type ? (object)obj.GetType() : obj.ObjectID);
 }