Skip to content

Commit

Permalink
stableton API
Browse files Browse the repository at this point in the history
  • Loading branch information
IonutParau committed Jul 1, 2023
1 parent 528b605 commit 747f119
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/logic/update/stableton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class StabletonData {
required this.decaysInto,
required this.decayRecursion,
});

@override
String toString() =>
"UNIT: $unitConstant\nLAYERS: $layerConstants\nOffsets: $offsets\nSwaps: $swapOffsets\nStationary: $stationary\nClonable: $clonable\nDecays Into: $decaysInto\nDecay Recursion: $decayRecursion";
}

final stabletonOrder = ["stable_a", "stable_b", "stable_c", "stable_d", "stable_i", "stable_j", "stable_k", "stable_n", "stable_p", "stable_s", "stable_o"];
Expand Down
113 changes: 113 additions & 0 deletions lib/scripts/lua_scripting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1922,11 +1922,124 @@ class LuaScript {
"Channel": channelAPI(),
"Types": typesAPI(),
"Time": timeAPI(),
"Stableton": stabletonAPI(),
};

ls.makeLib("TPC", tpcAPI);
}

Map<String, dynamic> stabletonAPI() {
return {
"registerStableton": (LuaState ls) {
int top = ls.top;
int arg(int i) {
return i - top - (ls.top - top);
}

final id = ls.toStr(arg(1))!;
final unitConstant = ls.toInteger(arg(2));
var i = 0;
final layerConstants = <int>[];

while (true) {
i++;
ls.pushInteger(i);
ls.getTable(arg(3));
if (ls.isNilOrNone(-1)) {
break; // end of list reached
}
layerConstants.add(ls.toInteger(-1));
ls.pop();
}

final offsets = <(int, int)>[];

i = 0;
while (true) {
i++;
ls.pushInteger(i);
ls.getTable(arg(4));
if (ls.isNilOrNone(-1)) {
break;
}
ls.pushString("x");
ls.getTable(-2);
final x = ls.toInteger(-1);
ls.pop();

ls.pushString("y");
ls.getTable(-2);
final y = ls.toInteger(-1);
ls.pop();

ls.pop();

offsets.add((x, y));
}

final swapOffsets = <(int, int)>[];

i = 0;
while (true) {
i++;
ls.pushInteger(i);
ls.getTable(arg(5));
if (ls.isNilOrNone(-1)) {
break;
}
ls.pushString("x");
ls.getTable(-2);
final x = ls.toInteger(-1);
ls.pop();

ls.pushString("y");
ls.getTable(-2);
final y = ls.toInteger(-1);
ls.pop();

ls.pop();

swapOffsets.add((x, y));
}

final stationary = ls.toBoolean(arg(6));
final clonable = ls.toBoolean(arg(7));

final decaysInto = <String>[];

i = 0;
while (true) {
i++;
ls.pushInteger(i);
ls.getTable(arg(8));
if (ls.isNilOrNone(-1)) {
break;
}

decaysInto.add(ls.toStr(-1)!);
ls.pop();
}

final decaysRecursion = ls.toInteger(arg(9));

stabletonOrder.add(id);
stabletonData[id] = StabletonData(
unitConstant: unitConstant,
layerConstants: layerConstants,
offsets: offsets,
swapOffsets: swapOffsets,
stationary: stationary,
clonable: clonable,
decaysInto: decaysInto,
decayRecursion: decaysRecursion,
);
print(stabletonOrder);
print(stabletonData[id]);
return 0;
},
};
}

int importOther(LuaState ls) {
final str = ls.toStr(-1) ?? "";
final status = ls.loadFile(path.joinAll([dir.path, ...str.split('/')]));
Expand Down
Binary file added mods/testmod/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions mods/testmod/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TPC.DefineCell({
id = "testcell",
name = "Test Cell",
desc = "Just a test cell",
category = "Base",
})

TPC.Stableton.registerStableton("testcell", 5, { -1, 1, 2, -2 },
{ { x = 1, y = 0 }, { x = -1, y = 0 }, { x = 0, y = 1 }, { x = 0, y = -1 } }, {}, true, false, {}, 0)
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@ flutter:
- assets/audio/
- languages/
- mods/
- mods/testmod/
- modules/
- markdown/

0 comments on commit 747f119

Please sign in to comment.