FormList Pseudocode

From the CreationKit Wiki
Revision as of 18:36, 7 March 2022 by BellCube (talk | contribs) (Create Page with Glitch's pseudocode)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Pseudocode for the FormList by Glitchfinder, uploaded at their request.

class FormList

  OrderedList scriptForms;
  OrderedList pluginForms;

  FormList(OrderedList plugin) {
    scriptForms = new OrderedList();
    pluginForms = plugin;
  }

  void AddForm(Form newForm) {
    if (scriptForms.Contains(newForm))
      return;

    scriptForms.Append(newForm);
  }

  int Find(Form findForm) {
    if (scriptForms.Contains(findForm))
      return scriptForms.IndexOf(findForm);

    if (pluginForms.Contains(findForm))
      return scriptForms.Length + pluginForms.IndexOf(findForm);

    return -1;
  }

  Form GetAt(int formIndex) {
    if (scriptForms.Length > formIndex)
      return scriptForms[formIndex];

    formIndex -= scriptForms.Length;

    if (pluginForms.Length > formIndex)
      return pluginForms[formIndex];

    return None;
  }

  int GetSize() {
    // Untested, therefore, an assumption
    return scriptForms.Length + pluginForms.Length;
  }

  bool HasForm(Form testForm) {
    if (scriptForms.Contains(testForm))
      return true;

    return pluginForms.Contains(testForm);
  }

  void RemoveAddedForm(Form removeForm) {
    scriptForms.Remove(removeForm);
  }

  void Revert() {
    scriptForms.Clear()
  }
}