Skip to content

Commit

Permalink
Merge pull request #35 from Master-Bw3/dev
Browse files Browse the repository at this point in the history
Merging untested changes into master because I dont care anymore
  • Loading branch information
Master-Bw3 authored Sep 9, 2023
2 parents 932e8b3 + 374a501 commit ba91703
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 5 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ https://master-bw3.github.io/Hex-Studio/
## Features
- Save/load projects
- Export pattern list to give command
- Emulates actions[\*] as you add patterns
- Simulated stack/Ravenmind (With input fields to handle unknowns)
- Step through your hex through the timeline bar
- Partial support for offhand/entities

[\*] Hex addons are not supported yet
## Attribution
Number Literal Generation uses https://github.com/object-Object/hexnumgen-rs
- Number Literal Generation uses https://github.com/object-Object/hexnumgen-rs
- Swindler's Gambit implemented by Aly
1 change: 1 addition & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"elm-community/array-extra": "2.6.0",
"elm-community/json-extra": "4.3.0",
"elm-community/list-extra": "8.7.0",
"elm-community/maybe-extra": "5.3.0",
"ianmackenzie/elm-geometry": "3.9.1",
"ianmackenzie/elm-units": "2.9.0",
"jinjor/elm-contextmenu": "2.0.0",
Expand Down
160 changes: 159 additions & 1 deletion gen/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -13054,6 +13054,164 @@ var $author$project$Logic$App$Patterns$Stack$swap = F2(
});
return A5($author$project$Logic$App$Patterns$OperatorUtils$action2Inputs, stack, ctx, $author$project$Logic$App$Patterns$OperatorUtils$getAny, $author$project$Logic$App$Patterns$OperatorUtils$getAny, action);
});
var $elm$core$Maybe$map2 = F3(
function (func, ma, mb) {
if (ma.$ === 1) {
return $elm$core$Maybe$Nothing;
} else {
var a = ma.a;
if (mb.$ === 1) {
return $elm$core$Maybe$Nothing;
} else {
var b = mb.a;
return $elm$core$Maybe$Just(
A2(func, a, b));
}
}
});
var $author$project$Logic$App$Patterns$Stack$swizzle = F2(
function (stack, ctx) {
var newStack = A3(
$elm$core$Array$slice,
1,
$elm$core$Array$length(stack),
stack);
var maybeIota = A2($elm$core$Array$get, 0, stack);
if (maybeIota.$ === 1) {
return {
a$: ctx,
fp: A2(
$elm$core$Array$append,
$elm$core$Array$fromList(
_List_fromArray(
[
$author$project$Logic$App$Types$Garbage(1)
])),
newStack),
bg: false
};
} else {
var iota = maybeIota.a;
var _v1 = $author$project$Logic$App$Patterns$OperatorUtils$getInteger(iota);
if (_v1.$ === 1) {
return {
a$: ctx,
fp: A2(
$author$project$Logic$App$Utils$Utils$unshift,
$author$project$Logic$App$Types$Garbage(2),
newStack),
bg: false
};
} else {
if (!iota.$) {
var number = iota.a;
var permutationSizeRec = F3(
function (accum, accumFact, input) {
permutationSizeRec:
while (true) {
if (_Utils_cmp(input, accumFact) < 0) {
return accum;
} else {
var next = 1 + accum;
var $temp$accum = next,
$temp$accumFact = next * accumFact,
$temp$input = input;
accum = $temp$accum;
accumFact = $temp$accumFact;
input = $temp$input;
continue permutationSizeRec;
}
}
});
var permutationSize = A2(permutationSizeRec, 1, 1);
var idxToCode = F2(
function (i, permSize) {
if (permSize <= 1) {
return _List_fromArray(
[0]);
} else {
var fact = function (n) {
if (!n) {
return 1;
} else {
var x = n;
return x * fact(x - 1);
}
};
var multiplier = fact(permSize - 1);
var digit = (i / multiplier) | 0;
return A2(
$elm$core$List$cons,
digit,
A2(idxToCode, i % multiplier, permSize - 1));
}
});
var idx = $elm$core$Basics$round(number);
var ps = permutationSize(idx);
var codeToPermutationReverse = F2(
function (c, remaining) {
if (!c.b) {
return $elm$core$Maybe$Just(_List_Nil);
} else {
var h = c.a;
var t = c.b;
var next = A2($elm_community$array_extra$Array$Extra$removeAt, h, remaining);
var elem = A2($elm$core$Array$get, h, remaining);
return A3(
$elm$core$Maybe$map2,
$elm$core$List$cons,
elem,
A2(codeToPermutationReverse, t, next));
}
});
var code = A2(idxToCode, idx, ps);
var oldSlice = $elm_community$array_extra$Array$Extra$reverse(
A3(
$elm$core$Array$slice,
0,
$elm$core$List$length(code),
newStack));
var maybeNewSlice = A2(
$elm$core$Maybe$map,
$elm$core$List$reverse,
A2(codeToPermutationReverse, code, oldSlice));
if (maybeNewSlice.$ === 1) {
return {
a$: ctx,
fp: A2(
$author$project$Logic$App$Utils$Utils$unshift,
$author$project$Logic$App$Types$Garbage(1),
stack),
bg: false
};
} else {
var newSlice = maybeNewSlice.a;
return {
a$: ctx,
fp: A2(
$elm$core$Array$append,
$elm$core$Array$fromList(newSlice),
A3(
$elm$core$Array$slice,
$elm$core$List$length(code),
$elm$core$Array$length(newStack),
newStack)),
bg: true
};
}
} else {
return {
a$: ctx,
fp: A2(
$author$project$Logic$App$Utils$Utils$unshift,
$author$project$Logic$App$Types$Garbage(12),
stack),
bg: false
};
}
}
}
});
var $elm$core$Basics$tan = _Basics_tan;
var $author$project$Logic$App$Patterns$Math$tangent = F2(
function (stack, ctx) {
Expand Down Expand Up @@ -13862,7 +14020,7 @@ function $author$project$Logic$App$Patterns$PatternRegistry$cyclic$patternRegist
{a: $author$project$Logic$App$Patterns$Stack$duplicateN, dY: 'Gemini Gambit', em: 'duplicate_n', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'aadaadaa', dr: 2},
{a: $author$project$Logic$App$Patterns$Stack$fisherman, dY: 'Fisherman\'s Gambit', em: 'fisherman', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'ddad', dr: 2},
{a: $author$project$Logic$App$Patterns$Stack$fishermanCopy, dY: 'Fisherman\'s Gambit II', em: 'fisherman/copy', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'aada', dr: 2},
{a: $author$project$Logic$App$Patterns$PatternRegistry$noAction, dY: '', em: 'swizzle', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'qaawdde', dr: 2},
{a: $author$project$Logic$App$Patterns$Stack$swizzle, dY: 'Swindler\'s Gambit', em: 'swizzle', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'qaawdde', dr: 2},
{a: $author$project$Logic$App$Patterns$Math$add, dY: 'Additive Distillation', em: 'add', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'waaw', dr: 2},
{a: $author$project$Logic$App$Patterns$Math$subtract, dY: 'Subtractive Distillation', em: 'sub', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'wddw', dr: 2},
{a: $author$project$Logic$App$Patterns$Math$mulDot, dY: 'Multiplicative Distillation', em: 'mul_dot', bE: _List_Nil, _: $elm$core$Maybe$Nothing, fn: 'waqaw', dr: 2},
Expand Down
2 changes: 1 addition & 1 deletion src/Logic/App/Patterns/PatternRegistry.elm
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ patternRegistry =
, { signature = "aadaadaa", internalName = "duplicate_n", action = duplicateN, displayName = "Gemini Gambit", outputOptions = [], selectedOutput = Nothing, startDirection = East }
, { signature = "ddad", internalName = "fisherman", action = fisherman, displayName = "Fisherman's Gambit", outputOptions = [], selectedOutput = Nothing, startDirection = East }
, { signature = "aada", internalName = "fisherman/copy", action = fishermanCopy, displayName = "Fisherman's Gambit II", outputOptions = [], selectedOutput = Nothing, startDirection = East }
, { signature = "qaawdde", internalName = "swizzle", action = noAction, displayName = "", outputOptions = [], selectedOutput = Nothing, startDirection = East } -- do this
, { signature = "qaawdde", internalName = "swizzle", action = swizzle, displayName = "Swindler's Gambit", outputOptions = [], selectedOutput = Nothing, startDirection = East } -- do this
, { signature = "waaw", internalName = "add", action = add, displayName = "Additive Distillation", outputOptions = [], selectedOutput = Nothing, startDirection = East }
, { signature = "wddw", internalName = "sub", action = subtract, displayName = "Subtractive Distillation", outputOptions = [], selectedOutput = Nothing, startDirection = East }
, { signature = "waqaw", internalName = "mul_dot", action = mulDot, displayName = "Multiplicative Distillation", outputOptions = [], selectedOutput = Nothing, startDirection = East }
Expand Down
74 changes: 74 additions & 0 deletions src/Logic/App/Patterns/Stack.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module Logic.App.Patterns.Stack exposing (..)

import Array exposing (Array)
import Array.Extra as Array
import FontAwesome.Attributes exposing (stack)
import Html.Attributes exposing (action)
import Logic.App.Patterns.OperatorUtils exposing (action1Input, action2Inputs, action3Inputs, actionNoInput, getAny, getInteger)
import Logic.App.Types exposing (ActionResult, CastingContext, Iota(..), Mishap(..))
import Logic.App.Utils.Utils exposing (removeFromArray, unshift)
import Maybe.Extra as Maybe


swap : Array Iota -> CastingContext -> ActionResult
Expand Down Expand Up @@ -206,3 +208,75 @@ fishermanCopy stack ctx =

_ ->
{ stack = unshift (Garbage CatastrophicFailure) stack, ctx = ctx, success = False }

swizzle : Array Iota -> CastingContext -> ActionResult
swizzle stack ctx =
let
maybeIota =
Array.get 0 stack

newStack =
Array.slice 1 (Array.length stack) stack
in
case maybeIota of
Nothing ->
{ stack = Array.append (Array.fromList [ Garbage NotEnoughIotas ]) newStack, ctx = ctx, success = False }

Just iota ->
case getInteger <| iota of
Nothing ->
{ stack = unshift (Garbage IncorrectIota) newStack, ctx = ctx, success = False }

_ ->
case iota of
Number number ->
-- HexCasting does something weird here I don't know how to replicate
-- [0, 1, 1.5, Swindle] will error on the 0 with an error message about 1.5
-- Very odd.
let
permutationSizeRec accum accumFact input =
if input < accumFact then accum
else let next = 1 + accum in permutationSizeRec next (next * accumFact) input

permutationSize = permutationSizeRec 1 1

idx = round number
ps = permutationSize idx

idxToCode : Int -> Int -> List Int
idxToCode i permSize =
if permSize <= 1 then [0]
else
let
fact n =
case n of
0 -> 1
x -> x * fact (x - 1)

multiplier = fact (permSize - 1)
digit = i // multiplier
in digit :: (idxToCode (remainderBy multiplier i) (permSize - 1))

code = idxToCode idx ps
oldSlice = Array.reverse (Array.slice 0 (List.length code) newStack)

codeToPermutationReverse c remaining =
case c of
[] -> Just []
h :: t ->
let
elem = Array.get h remaining
next = Array.removeAt h remaining
in Maybe.map2 (::) elem (codeToPermutationReverse t next)

maybeNewSlice = Maybe.map List.reverse (codeToPermutationReverse code oldSlice)
in case maybeNewSlice of
Nothing ->
-- needs to be more garbage iotas here to represent reality
{ stack = unshift (Garbage NotEnoughIotas) stack, ctx = ctx, success = False }

Just newSlice ->
{ stack = Array.append (Array.fromList newSlice) (Array.slice (List.length code) (Array.length newStack) newStack), ctx = ctx, success = True }

_ ->
{ stack = unshift (Garbage CatastrophicFailure) stack, ctx = ctx, success = False }

0 comments on commit ba91703

Please sign in to comment.