Example #1
0
 void StartHover(TriggerableBasePiece trap)
 {
     if (hover_routine != null)
     {
         StopCoroutine(hover_routine);
     }
     hover_routine = StartCoroutine(HoverRoutine(trap));
 }
Example #2
0
    IEnumerator HoverRoutine(TriggerableBasePiece trap)
    {
        while (true)
        {
            yield return(null);

            build_manager.link.SetLinkHighlight(trap);
        }
    }
Example #3
0
 void SetToLinkTriggeable(TriggerableBasePiece triggerable)
 {
     if (triggerable_to_trigger.ContainsKey(triggerable))
     {
         return;
     }
     to_link_triggerable = triggerable;
     triggerable.editor.SetHighlight();
 }
Example #4
0
 public void SetLinkHighlight(TriggerBasePiece to_highlight)
 {
     ClearLinkHighlight();
     trigger_highlight = to_highlight;
     trigger_highlight.editor.SetViewMode(BasePieceEditor.ViewMode.Highlight);
     if (trigger_to_triggerable.ContainsKey(to_highlight))
     {
         triggerable_highlight = trigger_to_triggerable[to_highlight];
         triggerable_highlight.editor.SetViewMode(BasePieceEditor.ViewMode.Highlight);
     }
 }
Example #5
0
 public void DeleteLink(TriggerBasePiece trigger, TriggerableBasePiece triggerable)
 {
     if (triggerable_to_trigger.ContainsKey(triggerable) && triggerable_to_trigger[triggerable] == trigger)
     {
         triggerable_to_trigger.Remove(triggerable);
     }
     if (trigger_to_triggerable.ContainsKey(trigger) && trigger_to_triggerable[trigger] == triggerable)
     {
         trigger_to_triggerable.Remove(trigger);
     }
     map_changed_event.Invoke();
 }
Example #6
0
 public void ClearLinkHighlight()
 {
     if (triggerable_highlight != null)
     {
         triggerable_highlight.editor.SetNormal();
     }
     if (trigger_highlight != null)
     {
         trigger_highlight.editor.SetNormal();
     }
     trigger_highlight     = null;
     triggerable_highlight = null;
 }
Example #7
0
 void ClearToLink()
 {
     if (to_link_trigger != null)
     {
         to_link_trigger.editor.SetNormal();
     }
     if (to_link_triggerable != null)
     {
         to_link_triggerable.editor.SetNormal();
     }
     to_link_trigger     = null;
     to_link_triggerable = null;
 }
Example #8
0
 public void CreateLink(TriggerBasePiece trigger, TriggerableBasePiece triggerable)
 {
     if (trigger == null || triggerable == null)
     {
         return;
     }
     if (triggerable_to_trigger.ContainsKey(triggerable) || trigger_to_triggerable.ContainsKey(trigger))
     {
         return;
     }
     triggerable_to_trigger.Add(triggerable, trigger);
     trigger_to_triggerable.Add(trigger, triggerable);
     map_changed_event.Invoke();
 }
Example #9
0
    public bool Load(BaseData data)
    {
        if (data == null)
        {
            return(false);
        }

        ClearMap();

        entrance_position = new Vector2Int(data.entrance_x, data.entrance_y);
        exit_position     = new Vector2Int(data.exit_x, data.exit_y);

        size.x = data.width;
        size.y = data.height;
        for (int x = 0; x < data.base_pieces_by_id.GetLength(0); x++)
        {
            for (int y = 0; y < data.base_pieces_by_id.GetLength(1); y++)
            {
                BaseData.BasePieceData piece_data = data.base_pieces_by_id[x, y];
                if (piece_data != null && piece_data.id > 0)
                {
                    PlacePiece(Database.base_pieces.GetBasePieceFromID(piece_data.id), piece_data.position, piece_data.facing);
                }
            }
        }

        for (int i = 0; i < data.triggerables.Length; i++)
        {
            TriggerBasePiece     trigger     = triggers[data.triggers[i].position];
            TriggerableBasePiece triggerable = triggerables[data.triggerables[i].position];

            trigger_to_triggerable.Add(trigger, triggerable);
            triggerable_to_trigger.Add(triggerable, trigger);
        }

        foreach (BaseData.EnemyGroupData enemy in data.enemy_group_by_id)
        {
            if (enemy != null && enemy.id > 0)
            {
                PlaceEnemy(Database.enemy_groups.GetEnemyGroupFromID(enemy.id), enemy.position, enemy.facing);
            }
        }

        map_valid = ValidateMap();

        return(true);
    }
Example #10
0
    public void RefreshUI()
    {
        for (int i = link_display_holder.childCount - 1; i >= 0; i--)
        {
            Destroy(link_display_holder.GetChild(i).gameObject);
        }

        foreach (KeyValuePair <TriggerableBasePiece, TriggerBasePiece> kvp in build_manager.triggerable_to_trigger)
        {
            TriggerableBasePiece trap    = kvp.Key;
            TriggerBasePiece     trigger = kvp.Value;

            LinkDisplay new_link_display = Instantiate(link_display_prefab, link_display_holder);

            new_link_display.trap_title    = trap.piece_name;
            new_link_display.trigger_title = trigger.piece_name;

            new_link_display.delete_button.onClick.AddListener(() => { build_manager.DeleteLink(trigger, trap); EndHover(); });

            new_link_display.SetEnterAction(() => StartHover(trap));
            new_link_display.SetExitAction(() => EndHover());
        }
    }
Example #11
0
    public bool Load(BaseData data)
    {
        if (data == null || !data.map_valid)
        {
            return(false);
        }
        loaded_map = data;

        pieces         = new Dictionary <Vector2Int, BasePiece>();
        enemies        = new List <Enemy>();
        killed_enemies = new List <Enemy>();

        entrance_position = new Vector2Int(data.entrance_x, data.entrance_y);

        exit_position = new Vector2Int(data.exit_x, data.exit_y);

        size.x = data.width;
        size.y = data.height;
        for (int x = 0; x < data.base_pieces_by_id.GetLength(0); x++)
        {
            for (int y = 0; y < data.base_pieces_by_id.GetLength(1); y++)
            {
                BaseData.BasePieceData piece_data = data.base_pieces_by_id[x, y];
                if (piece_data != null && piece_data.id > 0)
                {
                    Vector2Int position = new Vector2Int(x, y);
                    BasePiece  piece    = SpawnBasePiece(Database.base_pieces.GetBasePieceFromID(piece_data.id), piece_data.position, piece_data.facing);
                    piece.Init(false);
                    pieces.Add(piece_data.position, piece);
                    piece.position = piece_data.position;
                    piece.facing   = piece_data.facing;
                    if (position == exit_position)
                    {
                        exit = piece.GetComponentInChildren <Exit>();
                    }
                }
            }
        }


        // Connect Traps to Triggers
        for (int i = 0; i < data.triggers.Length && i < data.triggerables.Length; i++)
        {
            TriggerableBasePiece triggerable = (TriggerableBasePiece)pieces[data.triggerables[i].position];
            TriggerBasePiece     trigger     = (TriggerBasePiece)pieces[data.triggers[i].position];
            triggerable.SetTriggerHitbox(trigger.trigger_hitbox);
        }

        foreach (BaseData.EnemyGroupData enemy_data in data.enemy_group_by_id)
        {
            if (enemy_data != null && enemy_data.id > 0)
            {
                EnemyGroup group = SpawnEnemyGroup(Database.enemy_groups.GetEnemyGroupFromID(enemy_data.id), enemy_data.position, enemy_data.facing);

                enemies.AddRange(group.SpawnEnemies());
            }
        }

        foreach (Enemy enemy in enemies)
        {
            enemy.on_die_event.AddListener((Enemy e) => NoteEnemyDeath(e));
        }

        character.transform.position = (Vector3)entrance_position.ToVector3Int(Vector3Axis.y) * scale * block_size;

        return(true);
    }