Example #1
0
        void RenderMapInView(BufferJobData <MapViewBuffer> viewData, TerminalJobContext termData)
        {
            var mapData       = new MapJobContext(this, GetSingletonEntity <Map>(), true);
            var tileAssetsCTX = new MapTileAssetsBufferJobContext(this, true);

            Job.WithReadOnly(mapData)
            .WithReadOnly(viewData)
            .WithCode(() =>
            {
                var map  = mapData.Grid;
                var term = termData.GetAccessor();
                var view = viewData.GetArray <bool>();

                var tileAssets = tileAssetsCTX.Tiles;

                if (view.Length == 0)
                {
                    return;
                }

                TerminalTile t = TerminalTile.Default;

                for (int i = 0; i < view.Length; ++i)
                {
                    if (view[i])
                    {
                        int tileType = (int)map[i];
                        t            = tileAssets[tileType];
                        term[i]      = t;
                    }
                }
            }).Schedule();
        }
Example #2
0
 void ClearScreen(TerminalJobContext terminalData)
 {
     Job
     //.WithoutBurst()
     .WithCode(() =>
     {
         var term = terminalData.GetAccessor();
         term.ClearScreen();
     }).Schedule();
 }
Example #3
0
        void RenderActorsInView(BufferJobData <MapViewBuffer> viewData, TerminalJobContext termData)
        {
            Entities
            //.WithoutBurst()
            .WithAll <Actor>()
            .ForEach((in Position pos, in Renderable renderable) =>
            {
                var view = viewData.GetArray <bool>();
                var term = termData.GetAccessor();

                int i = Grid2D.PosToIndex(pos, term.Width);
                if (view[i])
                {
                    term[i] = renderable.ToTile();
                }
            }).Schedule();
Example #4
0
        protected override void OnUpdate()
        {
            var terminalEntity = _termQuery.GetSingletonEntity();
            var jobData        = new TerminalJobContext(this, terminalEntity, false);

            Entities
            .WithChangeFilter <UILogBuffer, HitPointsUI>()
            //.WithoutBurst()
            .ForEach((
                         ref DynamicBuffer <UILogBuffer> logBuffer,
                         in HitPointsUI hp) =>
            {
                var term = jobData.GetAccessor();

                if (term.Length == 0)
                {
                    return;
                }

                term.ClearScreen();
                term.DrawBorder();

                var emptyColor = new Color(0.05f, 0.05f, 0.05f);

                FixedString128 hpString = $"HP: {hp.current} / {hp.max}";

                int barWidth = term.Width - 20;
                int barX     = term.Width - barWidth - 1;
                int hpX      = barX - hpString.Length - 1;

                term.PrintFGColor(hpX, term.Height - 1, hpString, Color.yellow);
                term.DrawHorizontalBar(
                    term.Width - barWidth - 1,
                    term.Height - 1,
                    barWidth,
                    hp.current, hp.max,
                    Color.red, emptyColor);

                int lineCount = 0;
                for (int i = logBuffer.Length - 1;
                     i >= 0 && lineCount < term.Height - 2;
                     --i, ++lineCount)
                {
                    term.Print(2, term.Height - 2 - lineCount, logBuffer[i].Value);
                }
            }).Schedule();
        }