@painekillers/tree-builder-core 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/graph.js CHANGED
@@ -90,7 +90,7 @@ True: Connects back to existing instance of a node when recursing
90
90
  /*
91
91
  Strategies
92
92
  - [X] Current BFS (First) — Layer by shortest distance from root; first discovery determines placement.
93
- - [X] Undirected BFS (Undirected) — Shortest distance to root; layering is on directional.
93
+ - [X] Undirected BFS (Undirected) — Shortest distance to root; layering is one directional.
94
94
  - [X] Directed BFS, outward only (Outwards) — Follow prerequisite-to-dependent edges only.
95
95
  - [X] Furthest-parent layering (Furthest) — Place each node one layer below its deepest prerequisite.
96
96
  */
@@ -116,13 +116,13 @@ export class LayoutGraph {
116
116
  const visited = new Map()
117
117
  const connections = new Set()
118
118
 
119
- const addConnection = (ln, from) => {
119
+ const addConnection = (ln, from, lnPos) => {
120
120
  const fromNode =
121
121
  this.layers.get(from.layer)?.[from.ind]
122
122
 
123
123
  if(!fromNode) return
124
124
 
125
- const a = `${ln.layer}:${ln.ind}`
125
+ const a = `${lnPos.layer}:${lnPos.ind}`
126
126
  const b = `${from.layer}:${from.ind}`
127
127
 
128
128
  const key = [a, b].sort().join("|")
@@ -166,7 +166,7 @@ export class LayoutGraph {
166
166
  //holy crap i cannot think bruh
167
167
  if(((recurse === false) || (recurse === null)) && pos.layer !== layer) {
168
168
  if (
169
- recurse == null ||
169
+ recurse === null ||
170
170
  strategy == "Outwards" &&
171
171
  from !== null &&
172
172
  Math.abs(layer) < Math.abs(from.layer)
@@ -181,12 +181,13 @@ export class LayoutGraph {
181
181
  )
182
182
  ) { continue }
183
183
 
184
+ //this part makes the fake node btw
184
185
  const fn = new LayoutNode(node, layer, this.layers.get(pos.layer)[pos.ind])
185
186
  this.layers.get(layer).push(fn)
186
187
 
187
- addConnection(fn, from)
188
+ addConnection(fn, from, pos)
188
189
  } else {
189
- addConnection(ln, from)
190
+ addConnection(ln, from, pos)
190
191
 
191
192
  }
192
193
  }
@@ -200,14 +201,30 @@ export class LayoutGraph {
200
201
  Math.abs(layer) < Math.abs(from.layer)
201
202
  ) { continue }
202
203
 
203
- if (
204
- strategy == "Furthest" &&
205
- (
206
- (layer > 0 && !node.parents.every(val => visited.has(val.id)))
207
- ||
208
- (layer < 0 && !node.children.every(val => visited.has(val.id)))
209
- )
210
- ) { continue }
204
+ if (strategy == "Furthest") {
205
+ if (layer > 0 && !node.parents.every(val => visited.has(val.id))) {
206
+ for (const parent of node.parents) {
207
+ queue.push({
208
+ node: parent,
209
+ layer: layer - 1,
210
+ from: null
211
+ })
212
+ }
213
+
214
+ continue
215
+ } else
216
+ if (layer < 0 && !node.children.every(val => visited.has(val.id))) {
217
+ for (const child of node.children) {
218
+ queue.push({
219
+ node: child,
220
+ layer: layer + 1,
221
+ from: null
222
+ })
223
+ }
224
+
225
+ continue
226
+ }
227
+ }
211
228
 
212
229
  const ln = new LayoutNode(node, layer)
213
230
 
@@ -221,7 +238,7 @@ export class LayoutGraph {
221
238
  visited.set(key, pos)
222
239
 
223
240
  if(from) {
224
- addConnection(ln, from)
241
+ addConnection(ln, from, pos)
225
242
  }
226
243
 
227
244
  for (const child of node.children) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@painekillers/tree-builder-core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
package/themes/dark.js CHANGED
@@ -58,6 +58,7 @@ export default {
58
58
 
59
59
  node(ctx, object) {
60
60
  const pos = object.pos
61
+ const tile = object.tile
61
62
  const size = object.size
62
63
 
63
64
  const width = size.width * object.scale
@@ -104,13 +105,24 @@ export default {
104
105
 
105
106
  ctx.globalAlpha = object.hovered ? 1 : 0.92
106
107
 
107
- ctx.drawImage(
108
- object.image,
109
- x,
110
- y,
111
- width,
112
- height
113
- )
108
+ if (tile) {
109
+ ctx.drawImage(
110
+ object.image,
111
+ tile.x, tile.y, tile.width, tile.height,
112
+ x,
113
+ y,
114
+ width,
115
+ height,
116
+ )
117
+ } else {
118
+ ctx.drawImage(
119
+ object.image,
120
+ x,
121
+ y,
122
+ width,
123
+ height,
124
+ )
125
+ }
114
126
 
115
127
  ctx.restore()
116
128
 
package/themes/default.js CHANGED
@@ -140,6 +140,7 @@ export default {
140
140
  node(ctx, object) {
141
141
  const pos = object.pos
142
142
  const size = object.size
143
+ const tile = object.tile
143
144
 
144
145
  const width = size.width * object.scale
145
146
  const height = size.height * object.scale
@@ -173,13 +174,24 @@ export default {
173
174
 
174
175
  ctx.globalAlpha = object.hovered ? 1 : 0.92
175
176
 
176
- ctx.drawImage(
177
- object.image,
178
- x,
179
- y,
180
- width,
181
- height
182
- )
177
+ if (tile) {
178
+ ctx.drawImage(
179
+ object.image,
180
+ tile.x, tile.y, tile.width, tile.height,
181
+ x,
182
+ y,
183
+ width,
184
+ height,
185
+ )
186
+ } else {
187
+ ctx.drawImage(
188
+ object.image,
189
+ x,
190
+ y,
191
+ width,
192
+ height,
193
+ )
194
+ }
183
195
 
184
196
  ctx.restore()
185
197
 
package/world/bridge.js CHANGED
@@ -97,7 +97,8 @@ export default class Bridge {
97
97
  drawNode.height,
98
98
  drawNode.layoutNode.node,
99
99
  drawNode.layoutNode.node.val?.icon,
100
- drawNode
100
+ drawNode,
101
+ drawNode.layoutNode.node.val?.iconTile
101
102
  )
102
103
 
103
104
  obj.root =
package/world/objects.js CHANGED
@@ -100,11 +100,13 @@ placeholder.src = "data:image/svg+xml," + encodeURIComponent(`
100
100
 
101
101
  export class ImageInstance extends PSInstance {
102
102
  #image
103
+ #tile
103
104
 
104
- constructor(world, x, y, width, height, image) {
105
+ constructor(world, x, y, width, height, image, tile) {
105
106
  super(world, x, y, width, height)
106
107
 
107
108
  this.image = image
109
+ this.#tile = tile ?? null
108
110
  }
109
111
 
110
112
  set image(img) {
@@ -116,17 +118,37 @@ export class ImageInstance extends PSInstance {
116
118
  return this.#image ?? placeholder
117
119
  }
118
120
 
121
+ set tile(t) {
122
+ this.#tile = t
123
+ this.world.update()
124
+ }
125
+
126
+ get tile() {
127
+ return this.#tile
128
+ }
129
+
119
130
  draw(ctx, p, s) {
120
131
  let pos = p || this.pos
121
132
  let size = s || this.size
122
133
 
123
- ctx.drawImage(
124
- this.image,
125
- pos.x - size.width / 2,
126
- pos.y - size.height / 2,
127
- size.width,
128
- size.height
129
- )
134
+ if (this.#tile) {
135
+ ctx.drawImage(
136
+ this.image,
137
+ this.#tile.x, this.#tile.y, this.#tile.width, this.#tile.height,
138
+ pos.x - size.width / 2,
139
+ pos.y - size.height / 2,
140
+ size.width,
141
+ size.height,
142
+ )
143
+ } else {
144
+ ctx.drawImage(
145
+ this.image,
146
+ pos.x - size.width / 2,
147
+ pos.y - size.height / 2,
148
+ size.width,
149
+ size.height,
150
+ )
151
+ }
130
152
  }
131
153
  }
132
154
 
@@ -144,6 +166,7 @@ export class Line extends Object {
144
166
  }
145
167
  }
146
168
 
169
+ // Probably wanna change how this works too !!!!!!!!!!!
147
170
  export class NodeInstance extends ImageInstance {
148
171
  constructor(world, x, y, width, height, node, image, drawNode) {
149
172
  super(world, x, y, width, height, image)