Giter VIP home page Giter VIP logo

keeveegames / arraylist.gml Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 1.0 103 KB

The most complete list class for GameMaker Studio 2.3+. GC-friendly, [  ] accessor, 50+ functions (add, remove, insert, contains, find, sort, shuffle, reverse, etc.) and reference as array.

License: MIT License

Game Maker Language 100.00%
gamemaker gml accessor arraylist gms gms2 gamemaker-studio gamemaker-studio-2 array list gamemaker-language gamemaker-projects gamemaker-studio-2-3 gamemakerstudio gamemakerstudio2

arraylist.gml's Introduction

ArrayList.gml

Donate License

It is a custom List class / struct build on top of a standard GameMaker array. Works only with the 2.3+ version which introduced structs and constructors.

The advantages over ds_list or other struct realizations are: garbage collected, fast sort function, [] accessor and referencing as an array.

ArrayList is GC-friendly as it's basically an array inside of a struct so no need to manually destroy it as you do with the ds_list (although you can use delete on a ArrayList to dispose it explicitly).

There are some methods, including analogues of corresponding ds_list functions such as: add, remove, insert, sort, shuffle, reverse, copy and other.

Array reference is available from the struct in the array property and then can be passed anywhere or used with an accessor. Array reference is staying the same for the all lifecycle of struct so any changes made with that array will also reflects on the ArrayList and other way, if you pass that array somewhere (inside another data structure, draw it on GUI, etc.), all changes made with the ArrayList struct will also change the array. Basically you have all the array scripts ever written for GM available for this struct also.

So it is both an array and a list:

list = new ArrayList();

list.add("howdy", "ho", "world", "!");
list.remove(1);

list.array[0] = "hello";
array_resize(list.array, 2);

Weak parts are: slower than pure array or ds_list, no outside of bounds checking and possibility of losing the reference if reassign it explicitly via list.array = [], which you shouldn't do.

JSON Serialization:

You can easily encode/decode ArrayList to Json and vice versa with this packages:

Installation:

Get the latest asset package from the releases page. Import it into IDE.
Alternatively copy the code from corresponding scripts into your project.

Dependencies:

ArrayList is using quicksort package so you need to import this also if you do install as asset package and not from sources.

Syntax:

Example:

var list1 = new ArrayList([2, 4, 43, 50, 79, 36, 93, 54, 99, 26, 65, 69, 81, 63, 72, 3]);

list1.add(10, 9);

list1.remove(list1.size() - 2);

list1.insert(2, 5);

list1.array[2] = 6;
list1.array[list1.find_index(81)] = 18;

var list2 = new ArrayList();

list2.copy(list1);

list1.sort(true);
list2.shuffle();

show_debug_message(list1.array);
show_debug_message(list2.array);

Authors:

Nikita Musatov - MusNik / KeeVee Games

Contributors:

License: MIT

arraylist.gml's People

Contributors

keeveegames avatar sohomsahaun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

iconstudio

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.