ModernUO/Projects/UOContent/Engines/XMLSpawner/XmlTextEntryBook.cs
Kamron Batman 3882fbe599
use var
2024-02-12 19:14:16 -08:00

80 lines
2 KiB
C#

namespace Server.Items;
public class XmlTextEntryBook : BaseBook
{
public XmlTextEntryBook(int itemID, string title, string author, int pageCount, bool writable) : base(itemID, title, author, pageCount, writable)
{
}
public XmlTextEntryBook(Serial serial) : base(serial)
{
}
public void FillTextEntryBook(string text)
{
var pagenum = 0;
var current = 0;
// break up the text into single line length pieces
while (text != null && current < text.Length)
{
var lineCount = 10;
var lines = new string[lineCount];
// place the line on the page
for (var i = 0; i < lineCount; i++)
{
if (current < text.Length)
{
// make each line 25 chars long
var length = text.Length - current;
if (length > 20)
{
length = 20;
}
lines[i] = text.Substring(current, length);
current += length;
}
else
{
// fill up the remaining lines
lines[i] = string.Empty;
}
}
if (pagenum >= PagesCount)
{
return;
}
Pages[pagenum].Lines = lines;
pagenum++;
}
// empty the remaining contents
for (var j = pagenum; j < PagesCount; j++)
{
if (Pages[j].Lines.Length > 0)
{
for (var i = 0; i < Pages[j].Lines.Length; i++)
{
Pages[j].Lines[i] = string.Empty;
}
}
}
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
reader.ReadInt();
Delete();
}
}