Skip to content

Instantly share code, notes, and snippets.

View LuizMoratelli's full-sized avatar

Luiz Augusto Moratelli LuizMoratelli

View GitHub Profile
@LuizMoratelli
LuizMoratelli / AILogic.cs
Last active October 15, 2024 10:47
[TCGEngine] Stack Response
//replace(2x) Player player = data.GetPlayer(data.current_player); ->
Player player = data.response_phase == ResponsePhase.Response ? data.GetPlayer(data.response_player) : data.GetPlayer(data.current_player);
//replace(1x) Player player = data.GetPlayer(player_id); ->
Player player = data.response_phase == ResponsePhase.Response ? data.GetPlayer(data.response_player) : data.GetPlayer(data.current_player);
@LuizMoratelli
LuizMoratelli / readme.md
Last active October 11, 2024 13:43
[TCG Engine] Response Turn, interaction in opponent's turns.

First of all, this is a poc (proof of concept) be prepared to adapt, fix or encounter bugs for your specific game, I would be happy trying to help you.

Response Idea

The idea here is to allow some interaction between players in same turn. You can expand, adapt and change to fit your game, adding response on stack, or attack as response, is up to you.

What could be interacted following the steps below:

  • Selectors (Card, Target and Choice);
  • Play Cards with specific trait (similar to flash);
  • Activate Abilities;

The Problem

When you have sprites/images overlapping and you apply alpha (via CanvasGroup or direct) it allows the color/image behind to mix with the transparent one, displaying this annoying stuff when you have borders, lines, etc.

image

The Solution

1. Create a new Shader

@LuizMoratelli
LuizMoratelli / card-preview.md
Created August 12, 2024 13:56
[Odin] Card preview

Creating a Card Preview with Odin

1. Creating a PreviewCardScene

using UnityEditor.SceneManagement;
using UnityEngine;

public class PreviewCardScene : PreviewSceneStage
{
@LuizMoratelli
LuizMoratelli / readme.md
Last active September 9, 2024 00:49
[TCG Engine] 🤝 [mopsicus/uis]

0. Explanation

Mopsicus/UIs will be used to avoid a lot of instanciate of cards, that could cause some lags when you have a TON of cards. With this implementation, the Scroller will only spawn some rows, like ~7 and replace the values when the user scroll down and up.

1. Install mopsicus/uis (https://github.com/mopsicus/uis)

2. Edit CardData.cs

public static CardData GetCard(int index)
{
    if (index >= card_list.Count)
        return null;
@LuizMoratelli
LuizMoratelli / AILogic.cs
Last active February 17, 2025 16:39
[TcgEngine] Custom Mana System
private void CalculateNode(Game data, NodeState node)
{
//...
bool is_full_mana = HasAction(action_list, GameAction.PlayCard) && player.ManaMax() >= player.Mana();
//...
}
@LuizMoratelli
LuizMoratelli / create_so_and_attach.md
Created March 12, 2024 01:18
[Odin] Create a button to create and add reference to new SO

Simple and easy way to add a new button for create and attach an SO to another, this make easier to create abilities for cards in my game (removing the need of create the SO, find the card, and attach)

Result: image

In Editor.cs

public class MyDataProcessor : OdinAttributeProcessor<MyData>
{
@LuizMoratelli
LuizMoratelli / tcg-engine-meets-odin.md
Last active April 28, 2025 18:33
[TCG Engine] 🤝 [Odin]

1 Adding Attributes to Data classes

1.1 CardData.cs

  [HorizontalGroup("Info", Width = 325)]
  [VerticalGroup("Info/Side1", Order =2), LabelWidth(50)]
  public string id;

  [VerticalGroup("Info/Side1"), LabelWidth(50)]
  public string title;
  [VerticalGroup("Info/Side2"), PreviewField(100), HideLabel,]
@LuizMoratelli
LuizMoratelli / TextEnhanceData.cs
Last active March 28, 2024 19:55
[TCG Engine] Enhance Text at Preview
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
using System.Text.RegularExpressions;
namespace TcgEngine
{
[InlineButton("@CardEditor.CloneAction($root, $property, $value)", SdfIconType.FileEarmarkPlusFill, "", ShowIf = "@CardEditor.ShowNotNull($value)")]
[CreateAssetMenu(fileName = "textEnhancer", menuName = "TcgEngine/TextEnhancer", order = 99)]
@LuizMoratelli
LuizMoratelli / start-of-game.md
Last active December 11, 2023 07:42
[TCG Engine] Create Start of Game Effects

1. Create a new AbilityTrigger "StartOfGame" in AbilityData.cs

public enum AbilityTrigger {
  //...
  StartOfGame = 19, // On-time
  //...
}

2. Update GameLogic.cs to resolve "StartOfGame" Abilities before the 1st turn begins.