Пример #1
0
    private Dictionary <CellRecord, Scene> LoadCells()
    {
        var newCells = new Dictionary <CellRecord, Scene>();

        for (var x = -cellsToLoad; x <= cellsToLoad; x++)
        {
            for (var y = -cellsToLoad; y <= cellsToLoad; y++)
            {
                var coordinates = new Vector2Int(this.coordinates.x + x, this.coordinates.y + y);
                var cellRecord  = CellRecord.GetExteriorCell(coordinates);

                // Check to see if this cell is already loaded, if so, don't re-load it, just add it to the new list of loaded cells
                Scene scene;
                if (!loadedCells.TryGetValue(cellRecord, out scene))
                {
                    scene = LoadCell(cellRecord);
                }

                newCells.Add(cellRecord, scene);

                // If in the middle, set as current cell (Note, may be different to Unity's current cell
                if (x == 0 && y == 0)
                {
                    currentCell = cellRecord;
                }
            }
        }

        return(newCells);
    }
Пример #2
0
    // Returns a display-friendly name of an exterior cell, given a position
    public static string GetCellName(Vector3 position)
    {
        var coordinates = new Vector2Int(Mathf.FloorToInt(position.x / 8192), Mathf.FloorToInt(position.z / 8192));
        var cell        = CellRecord.GetExteriorCell(coordinates);

        return(string.IsNullOrEmpty(cell.Name) ? cell.Region.Name : cell.Name);
    }
Пример #3
0
    public static void LoadCell(string loadCell)
    {
        // Unload existing scenes
        foreach (var cell in Instance.loadedCells.Values)
        {
            SceneManager.UnloadSceneAsync(cell);
        }

        if (Instance.InteriorCell.IsValid())
        {
            SceneManager.UnloadSceneAsync(Instance.InteriorCell);
        }

        Instance.loadedCells.Clear();

        // Change this into an interface or something?
        if (string.IsNullOrEmpty(loadCell))
        {
            Instance.Start();
            Instance.enabled = true;
        }
        else
        {
            Instance.enabled = false;
            var cell = CellRecord.GetInteriorCell(loadCell);
            Instance.InteriorCell = LoadCell(cell);
            Instance.currentCell  = cell;
            OnFinishedLoadingCells?.Invoke(cell);
        }
    }
Пример #4
0
    private static Scene LoadCell(CellRecord cell)
    {
        // Save currently active scene so it can be restored later
        var activeScene = SceneManager.GetActiveScene();

        var sceneName = GetUniqueCellName(cell);
        var newScene  = SceneManager.CreateScene(sceneName);

        SceneManager.SetActiveScene(newScene);

        cell.CellData.LoadTerrain();
        StaticBatching.Clear();

        // Load the cell objects
        foreach (var reference in cell.ReferenceData)
        {
            var creatableData = reference.ObjectId;
            var clone         = creatableData.CreateGameObject(reference);

            // Levelled Creature records might not spawn a creature, so return
            if (clone != null)
            {
                reference.TransformData.SetTransformData(clone.transform);
                clone.transform.localScale = new Vector3(reference.Scale, reference.Scale, reference.Scale);
            }
        }

        StaticBatchingUtility.Combine(StaticBatching.ToArray(), new GameObject("Static Batch Root"));

        // Set the original scene as the active scene. This stops weather from changing when new cells are loaded
        SceneManager.SetActiveScene(activeScene);

        return(newScene);
    }
Пример #5
0
 private void AddMultipleCell(CellRecord cell)
 {
     var cells = cell as MultipleColCellRecord;
     for (ushort i = cells.FirstCol; i <= cells.LastCol; ++i)
     {
         object val = cells.GetValue(i);
         if (val != null)
             Cells.Add(i, new XLSCell(val));
     }
 }
Пример #6
0
 void ActivateCell(Vector2 cell, Vector2 parentcell)
 {
     if (m_Board [(int)cell.x, (int)cell.y].GetComponent <CellRecord> () == null)
     {
         //replace the cell with working set graphic, add a cell record to it, add it to working set
         ReplaceCell((int)cell.x, (int)cell.y, m_WorkingCellPrefab);
         CellRecord record = m_Board [(int)cell.x, (int)cell.y].AddComponent <CellRecord> ();
         record.Initialise(parentcell, cell);
         WorkingSet.Add(cell);
     }
 }
Пример #7
0
 private void AddCell(CellRecord cell)
 {
     if (cell is SingleColCellRecord)
     {
         Cells.Add((cell as SingleColCellRecord).Col, new XLSCell(cell.Value));
     }
     else if (cell is MultipleColCellRecord)
     {
         AddMultipleCell(cell);
     }
 }
Пример #8
0
 private void AddCell(CellRecord cell)
 {
     if (cell is SingleColCellRecord)
     {
         Cells.Add((cell as SingleColCellRecord).Col, new XLSCell(cell.Value));
     }
     else if (cell is MultipleColCellRecord)
     {
         AddMultipleCell(cell);
     }
 }
Пример #9
0
        private void AddMultipleCell(CellRecord cell)
        {
            var cells = cell as MultipleColCellRecord;

            for (ushort i = cells.FirstCol; i <= cells.LastCol; ++i)
            {
                object val = cells.GetValue(i);
                if (val != null)
                {
                    Cells.Add(i, new XLSCell(val));
                }
            }
        }
        public CellRecord GetElementsCell(int row, int col)
        {
            var i = (1 + row) * (1 + this.Cols) + (1 + col);

            if (row < 0 || col < 0 || this.Elements == null || i >= this.Elements.Count)
            {
                return(null);
            }
            var cr = new CellRecord(this.Elements[i]);

            cr.TextWithHeaders =
                this.Elements[0] + " " + this.Elements[(1 + row) * (1 + this.Cols)] + " " +
                this.Elements[1 + col] + " " + cr.Text;
            return(cr);
        }
Пример #11
0
    private static string GetUniqueCellName(CellRecord cell)
    {
        if (cell.CellData.IsInterior)
        {
            return(cell.Name);
        }

        if (string.IsNullOrEmpty(cell.Name))
        {
            return($"{cell.Region.Name} {cell.CellData.Coordinates}");
        }
        else
        {
            return($"{cell.Name} {cell.CellData.Coordinates}");
        }
    }
Пример #12
0
 private void SetupWater(CellRecord cell)
 {
     if (cell.CellData.IsInterior)
     {
         if (cell.CellData.HasWater)
         {
             projection.OceanLevel = cell.WaterHeight;
         }
         else
         {
             gameObject.SetActive(false);
         }
     }
     else
     {
         gameObject.SetActive(true);
     }
 }
Пример #13
0
    private void SwitchCell(CellRecord cell)
    {
        enabled = !cell.CellData.IsInterior;

        if (cell.CellData.IsInterior)
        {
            cell.AmbientData.SetRenderSettings();
            rain.SetActive(false);

            StopCoroutine(PlayEnvironmentalSounds(cell.Region));
        }
        else
        {
            var weatherChances = cell.Region.WeatherData.WeatherChances;

            // Calculate weather chances
            var maxChance = weatherChances.Sum((b) => b);
            var value     = Random.Range(0, maxChance);

            // Get a max value in the range of all the weather types, and choose a type
            for (var i = 0; i < weatherChances.Count; i++)
            {
                if (value < weatherChances[i])
                {
                    weatherType = (WeatherType)i;
                    break;
                }
                else
                {
                    value -= weatherChances[i];
                }
            }

            SetWeatherSettings(weatherType);
            StartCoroutine(PlayEnvironmentalSounds(cell.Region));
        }
    }
        //
        // Word
        //

        private void ExportWord_AppendTableCell(TableRow tr, CellRecord cr)
        {
            TableCell tc   = tr.AppendChild(new TableCell());
            Paragraph para = tc.AppendChild(new Paragraph());

            // see: https://stackoverflow.com/questions/17675526/
            // how-can-i-modify-the-foreground-and-background-color-of-an-openxml-tablecell/17677892

            if (cr.HorizAlign != null)
            {
                ParagraphProperties pp = new ParagraphProperties();

                if (cr.HorizAlign == "left")
                {
                    pp.Justification = new Justification()
                    {
                        Val = JustificationValues.Left
                    }
                }
                ;
                if (cr.HorizAlign == "center")
                {
                    pp.Justification = new Justification()
                    {
                        Val = JustificationValues.Center
                    }
                }
                ;
                if (cr.HorizAlign == "right")
                {
                    pp.Justification = new Justification()
                    {
                        Val = JustificationValues.Right
                    }
                }
                ;

                para.Append(pp);
            }

            if (cr.VertAlign != null || cr.Bg != null)
            {
                var tcp = tc.AppendChild(new TableCellProperties());

                if (cr.VertAlign == "top")
                {
                    tcp.Append(new TableCellVerticalAlignment()
                    {
                        Val = TableVerticalAlignmentValues.Top
                    });
                }
                if (cr.VertAlign == "center")
                {
                    tcp.Append(new TableCellVerticalAlignment()
                    {
                        Val = TableVerticalAlignmentValues.Center
                    });
                }
                if (cr.VertAlign == "bottom")
                {
                    tcp.Append(new TableCellVerticalAlignment()
                    {
                        Val = TableVerticalAlignmentValues.Bottom
                    });
                }

                if (cr.Bg != null)
                {
                    // ReSharper disable PossibleNullReferenceException
                    try
                    {
                        var bgc = (System.Windows.Media.Color)ColorConverter.ConvertFromString(cr.Bg);
                        var bgs = (new ColorConverter()).ConvertToString(bgc).Substring(3);

                        tcp.Append(new DocumentFormat.OpenXml.Wordprocessing.Shading()
                        {
                            Color = "auto",
                            Fill  = bgs,
                            Val   = ShadingPatternValues.Clear
                        });
                    }
                    catch (Exception ex)
                    {
                        AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                    }
                    // ReSharper enable PossibleNullReferenceException
                }
            }

            // var run = new Run(new Text(cr.Text));
            // make a run with multiple breaks
            var run   = new Run();
            var lines = cr.Text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var l in lines)
            {
                if (run.ChildElements != null && run.ChildElements.Count > 0)
                {
                    run.AppendChild(new Break());
                }
                run.AppendChild(new Text(l));
            }

            if (cr.Fg != null || cr.Font != null)
            {
                try
                {
                    var rp = new RunProperties();

                    if (cr.Fg != null)
                    {
                        var fgc = (System.Windows.Media.Color)ColorConverter.ConvertFromString(cr.Fg);
                        var fgs = (new ColorConverter()).ConvertToString(fgc).Substring(3);

                        rp.Append(new DocumentFormat.OpenXml.Wordprocessing.Color()
                        {
                            Val = fgs
                        });
                    }

                    if (cr.Font != null && cr.Font.Contains("bold"))
                    {
                        rp.Bold = new Bold();
                    }

                    if (cr.Font != null && cr.Font.Contains("italic"))
                    {
                        rp.Italic = new Italic();
                    }

                    if (cr.Font != null && cr.Font.Contains("underline"))
                    {
                        rp.Underline = new Underline();
                    }

                    run.RunProperties = rp;
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                }
            }

            para.Append(run);
        }
            public void ProcessCellRecord(CellRecord cr)
            {
                if (Record == null || regexReplacements == null || regexCommands == null)
                {
                    return;
                }

                // local
                var input = cr.Text;

                // newline
                if (this.ReplaceNewlineWith != null)
                {
                    input = input.Replace("\r\n", this.ReplaceNewlineWith);
                    input = input.Replace("\n\r", this.ReplaceNewlineWith);
                    input = input.Replace("\n", this.ReplaceNewlineWith);
                }

                // process from right to left
                // see: https://codereview.stackexchange.com/questions/119519/
                // regex-to-first-match-then-replace-found-matches
                var matchesReplace = regexReplacements.Matches(input);

                foreach (var match in matchesReplace.Cast <Match>().Reverse())
                {
                    if (match.Groups.Count < 2)
                    {
                        continue;
                    }

                    // OK, found a placeholder-tag to replace
                    var tag = "" + match.Groups[1].Value.Trim().ToLower();

                    if (this.repDict.ContainsKey(tag))
                    {
                        input = Replace(input, match.Index, match.Length, this.repDict[tag]);
                        this.NumberReplacements++;
                    }
                    else
                    {
                        // placeholder not found!
                        if (Record.ReplaceFailedMatches)
                        {
                            input = Replace(input, match.Index, match.Length, Record.FailText);
                        }
                    }
                }

                // commit back
                cr.Text = input;

                // for commands, use
                input = cr.TextWithHeaders;

                // evaluate commands
                var matchesCmd = regexCommands.Matches(input);

                foreach (var match in matchesCmd.Cast <Match>().Reverse())
                {
                    // access cmd
                    if (match.Groups.Count < 3)
                    {
                        continue;
                    }

                    var cmd   = match.Groups[1].ToString().Trim().ToLower();
                    var arg   = match.Groups[2].ToString();
                    var argtl = arg.Trim().ToLower();

                    switch (cmd)
                    {
                    case "fg":
                        cr.Fg = argtl;
                        break;

                    case "bg":
                        cr.Bg = argtl;
                        break;

                    case "halign":
                        cr.HorizAlign = argtl;
                        break;

                    case "valign":
                        cr.VertAlign = argtl;
                        break;

                    case "font":
                        cr.Font = argtl;
                        break;

                    case "frame":
                        cr.Frame = argtl;
                        break;
                    }

                    // in any case, replace the wohl match!
                    // input = Replace(input, match.Index, match.Length, "");
                }
            }
        //
        // Excel
        //

        private void ExportExcel_AppendTableCell(IXLWorksheet ws, CellRecord cr, int ri, int ci)
        {
            // access
            if (ws == null || cr == null)
            {
                return;
            }

            // basic cell
            var cell = ws.Cell(ri, ci);

            // always wrapping text
            cell.Value = "" + cr.Text;
            cell.Style.Alignment.WrapText = true;

            // alignments
            cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
            if (cr.HorizAlign != null)
            {
                if (cr.HorizAlign == "center")
                {
                    cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
                }
                if (cr.HorizAlign == "right")
                {
                    cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right;
                }
            }

            cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;
            if (cr.VertAlign != null)
            {
                if (cr.VertAlign == "center")
                {
                    cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
                }
                if (cr.VertAlign == "bottom")
                {
                    cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Bottom;
                }
            }

            // colors
            if (cr.Bg != null)
            {
                // ReSharper disable PossibleNullReferenceException
                try
                {
                    var bgc = (System.Windows.Media.Color)ColorConverter.ConvertFromString(cr.Bg);
                    cell.Style.Fill.BackgroundColor = XLColor.FromArgb(bgc.A, bgc.R, bgc.G, bgc.B);
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                }
                // ReSharper enable PossibleNullReferenceException
            }

            if (cr.Fg != null)
            {
                // ReSharper disable PossibleNullReferenceException
                try
                {
                    var fgc = (System.Windows.Media.Color)ColorConverter.ConvertFromString(cr.Fg);
                    cell.Style.Font.FontColor = XLColor.FromArgb(fgc.A, fgc.R, fgc.G, fgc.B);
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                }
                // ReSharper enable PossibleNullReferenceException
            }

            // font?
            if (cr.Font != null)
            {
                if (cr.Font.Contains("bold"))
                {
                    cell.Style.Font.Bold = true;
                }
                if (cr.Font.Contains("italic"))
                {
                    cell.Style.Font.Italic = true;
                }
                if (cr.Font.Contains("underline"))
                {
                    cell.Style.Font.Underline = XLFontUnderlineValues.Single;
                }
            }
        }
Пример #17
0
        internal Worksheet(Workbook wb, BoundSheetRecord sheet, SortedList <long, Biff> records)
            : base(wb)
        {
            _name = sheet.Name;

            int idx = records.IndexOfKey((long)sheet.BofPos);

            _hyperlinks = new HyperLinkCollection(wb);

            for (int i = idx + 1; i < records.Count; ++i)
            {
                Biff biff = records.Values[i];
                if (biff is HyperLinkRecord)
                {
                    _hyperlinks.Add((HyperLinkRecord)biff);
                }
                else if (biff is EofRecord)
                {
                    break;
                }
            }

            BofRecord bof = (BofRecord)records.Values[idx++];

            Biff seeker = records.Values[idx++];

            while (!(seeker is IndexRecord))
            {
                seeker = records.Values[idx++];
            }

            IndexRecord index = (IndexRecord)seeker;

            _rows = new RowCollection(wb);
            foreach (uint indexPos in index.Rows)
            {
                long         dbCellPos = indexPos;
                int          dbCellIdx = records.IndexOfKey(dbCellPos);
                DbCellRecord dbCell    = (DbCellRecord)records[dbCellPos];

                if (dbCell.RowOffset > 0)
                {
                    long rowPos   = dbCellPos - dbCell.RowOffset;
                    int  recIndex = records.IndexOfKey(rowPos);
                    Debug.Assert(recIndex != -1);

                    Biff record = records.Values[recIndex++];
                    while (record is RowRecord)
                    {
                        RowRecord row        = (RowRecord)record;
                        Row       currentRow = new Row(Workbook, row);
                        _rows.Add(row.RowNumber, currentRow);

                        record = records.Values[recIndex++];
                    }

                    while (recIndex <= dbCellIdx)
                    {
                        if (!(record is CellRecord))
                        {
                            record = records.Values[recIndex++];
                            continue;
                        }

                        CellRecord thecell    = (CellRecord)record;
                        Row        currentRow = _rows[thecell.Row];

                        if (thecell is SingleColCellRecord)
                        {
                            SingleColCellRecord cell = (SingleColCellRecord)thecell;
                            object val = cell.Value;

                            Cell newCell = new Cell(Workbook, val);
                            if (cell is RowColXfCellRecord)
                            {
                                RowColXfCellRecord xfCell = (RowColXfCellRecord)cell;

                                Style style = Workbook.Styles[xfCell.Xf];
                                Debug.Assert(style != null);
                                newCell.Style = style;
                            }
                            currentRow.Cells.Add((byte)cell.Col, newCell);
                        }
                        else
                        {
                            MultipleColCellRecord cells = (MultipleColCellRecord)thecell;
                            for (ushort i = cells.FirstCol; i <= cells.LastCol; ++i)
                            {
                                object val = cells.GetValue(i);
                                if (val != null)
                                {
                                    Cell newCell = null;
                                    if (val is RkRec)
                                    {
                                        RkRec rk = (RkRec)val;

                                        newCell = new Cell(Workbook, rk.Value);
                                        Style style = Workbook.Styles[rk.Xf];
                                        Debug.Assert(style != null);
                                        newCell.Style = style;
                                    }
                                    else
                                    {
                                        newCell = new Cell(Workbook, val);
                                    }

                                    currentRow.Cells.Add((byte)i, newCell);
                                }
                            }
                        }

                        record = records.Values[recIndex++];
                    }
                }
            }
        }
Пример #18
0
    public static void Create(BinaryReader reader)
    {
        var header = new RecordHeader(reader);

        switch (header.Type)
        {
        case RecordType.BirthSign:
            BirthSignRecord.Create(reader, header);
            break;

        case RecordType.BodyPart:
            BodyPartRecord.Create(reader, header);
            break;

        case RecordType.Cell:
            CellRecord.Create(reader, header);
            break;

        case RecordType.Dialogue:
            DialogRecord.Create(reader, header);
            break;

        case RecordType.GameSetting:
            GameSetting.Create(reader, header);
            break;

        case RecordType.Info:
            InfoRecord.Create(reader, header);
            break;

        case RecordType.Land:
            LandRecord.Create(reader, header);
            break;

        case RecordType.LandTexture:
            LandTextureRecord.Create(reader, header);
            break;

        case RecordType.MagicEffect:
            MagicEffectRecord.Create(reader, header);
            break;

        case RecordType.PathGrid:
            Pathgrid.Create(reader, header);
            break;

        case RecordType.Script:
            Script.Create(reader, header);
            break;

        case RecordType.Skill:
            SkillRecord.Create(reader, header);
            break;

        case RecordType.SoundGenerator:
            SoundGenerator.Create(reader, header);
            break;

        case RecordType.Tes3:
            Tes3Record.Create(reader, header);
            break;

        default:
        {
            var size = GotoSubrecord(SubRecordType.Id, header);
            var id   = reader.ReadString(size);
            reader.BaseStream.Position = header.DataOffset + header.DataSize;
            var recordData = CreateRecordData(header.Type);
            recordData.Header = header;
            Records.Add(id, recordData);
            break;
        }
        }
    }