Simple Module

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/UI }

# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.

SimpleModule := module:
    
    EasyTeamModule<public> := module:
        #TeamChange
        (Player : player).TeamSet<public>(Index : int):void=
            MC := MainClass{}
            MC.TeamSet(Player,Index)

        #GetTeamIndex
        (Player : player).GetTeamIndex<public>():int=
            MC := MainClass{}
            return MC.TeamIndex(Player)
        #Index team return
        GetTeamPlayers<public>(Index : int):[]player=
            MC := MainClass{}
            return MC.GetPlayer(Index)

    PlayersModule<public> := module:
        #Active player return
        LivePlayers<public>():[]player=
            MC := MainClass{}
            return MC.LivePlayers()

    EasyUIModule<public> := module:
        #UI set
        (Player : player).UISet<public>(Canvas : canvas):?canvas=
            MC := MainClass{}
            return MC.UISet(Player,Canvas)
        #UI Remove
        (Player : player).UIRemove<public>(Canvas : canvas):void=
            MC := MainClass{}
            return MC.UIRemove(Player,Canvas)




MainClass := class(creative_device):
    UIText<localizes>(Player : player,Index : int): message ="{Player} in {Index} team"
#EasyTeamModule
    TeamSet(Player : player,Index : int):void=
        TeamCol := GetPlayspace().GetTeamCollection()
        if(t := TeamCol.GetTeams()[Index],TeamCol.AddToTeam[Player,t]):
            Print(UIText(Player,Index))
        else:
            Print("TeamSetError")

    TeamIndex(Player : player):int=
        TeamCol := GetPlayspace().GetTeamCollection()
        for(Index -> _Team : TeamCol.GetTeams()):
            if(t := TeamCol.GetTeam[Player],t = _Team):
                Print("TeamIndex = {Index}")
                return Index
        Print("TeamGetError")
        return -1

    GetPlayer(Index : int)<transacts>:[]player=
        var Players : []player = array{}
        TeamCol := GetPlayspace().GetTeamCollection()
        if(Agents := TeamCol.GetAgents[TeamCol.GetTeams()[Index]]):
            for(Agent : Agents,Player := player[Agent]):
                set Players += array{Player}
        return Players
#PlayersModule
    LivePlayers()<transacts>:[]player=
        var Players : []player = array{}
        for:
            Player : GetPlayspace().GetPlayers()
            FortChar := Player.GetFortCharacter[]
        do:
            if(FortChar.IsActive[]):
                set Players += array{Player}
        return Players
#EasyUIModule
    UISet(Player : player,Canvas : canvas):?canvas=
        var c : ?canvas = false
        if(PlayerUI := GetPlayerUI[Player]):
            PlayerUI.AddWidget(Canvas)
            set c = option{Canvas}
        return c

    UIRemove(Player : player,Canvas : canvas):void=
        if(PlayerUI := GetPlayerUI[Player]):
            PlayerUI.RemoveWidget(Canvas)


#Memo
# canvas_slot:
#     Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.5}, Maximum := vector2{X := 0.5, Y := 0.5}}
#     Offsets := margin{Left := 0.0,Top := 0.0, Right := 0.0, Bottom := 0.0}
#     Alignment := vector2{X := 0.5, Y := 0.5}
#     SizeToContent := true
#     Widget := button_loud{DefaultText := TextForMyUI}

#DamageEvent
# OnDamaged(Result : damage_result):void=
#     if:
#         ap_f := fort_character[Result.Instigator?]
#         hp_f := fort_character[Result.Target]
#     then:
#         if:
#             ap := player[ap_f.GetAgent[]]
#             hp := player[hp_f.GetAgent[]]
#         then: