Skip to content

Instantly share code, notes, and snippets.

View happenslol's full-sized avatar
🎺
doot doot

Hilmar Wiegand happenslol

🎺
doot doot
View GitHub Profile
@happenslol
happenslol / git-dnor.bash
Last active March 5, 2021 15:48
Git CLI extensions
#!/bin/bash
# Deletes all local branches not present on remote
set -eo pipefail
git fetch -p && git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -D
// old
if to_place.x < to_split.x + to_split.width && to_place.x + to_place.width > to_split.x {
// New node at the top side of the placed node.
if to_place.y > to_split.y && to_place.y < to_split.y + to_split.height {
self.free.push(Rect {
y: to_place.y - to_split.y,
..to_split
})
}

Keybase proof

I hereby claim:

  • I am happenslol on github.
  • I am happenslol (https://keybase.io/happenslol) on keybase.
  • I have a public key ASBgiseoVV444REe3ufvaK3Zw774Ck5iqZTpdfNfNTLpvgo

To claim this, I am signing this object:

@happenslol
happenslol / patchwork-draft-1.rs
Created March 31, 2019 14:46
Layout and styling language, pre-alpha-concept-theory-idea-hypothesis (test 1)
// Not really happy with how styles look at tags are not in this
// yet, but this is the gist of it. There's probably some glaring flaws,
// but this is just what I threw together from the top of my head and will
// definitely need some more iterations anyways =padding
// I think the general idea comes across though.
struct FooData {
pub view_port: (u32, u32),
pub image_src: String,
pub counter: u32,
@happenslol
happenslol / label-lifetimes.rs
Created March 11, 2019 20:02
Lifetime issue with resources, builder and generics
#[derive(SystemData)]
// <- WidgetId/I needs to be 'a here...
pub struct UiLabelBuilderResources<'a, I: WidgetId + 'a = u32> {
entities: Entities<'a>,
label_widgets: WriteExpect<'a, Widgets<UiLabel, I>>, // <- because it needs to live as long as
// the resources we're using it on.
}
// Don't I need to define the lifetime for I here too? How would I even do that?
pub struct UiLabelBuilder<I: WidgetId> {

Alright, so first the basic things we can probably agree on.

There's going to be a generic System with associated types In and Out. It's called EventRetriggerSystem and its job is to take some sort of event In (in our case probably UiEvents, but arbitrary events in the future) and emit some kind of other event Out. It registers a reader to the In event queue when it starts up, and requires Write<EventChannel<Self::Out>> in its SystemData.

There's 2 things that are up for discussion here:

  • How generic should the Out events be, and should they be enum variants or structs? The resulting question from this is, does every "Variant" (whether it's an enum variant or a struct) require its own System?
  • Where and how should we store the mapping of what In leads to which Out?

Out event structure

extern crate amethyst;
use amethyst::{
core::TransformBundle,
input::InputBundle,
prelude::*,
renderer::{
PosNormTex, DrawShaded,
},
utils::application_root_dir,
use amethyst_core::{
shrev::{EventChannel, ReaderId},
specs::prelude::{
Component, Read, Write, ReadStorage, Resources, System, SystemData,
},
};
use event::TargetedEvent;
pub trait EventRetrigger: Component {
pub enum UiAction {
PlaySound,
SetTexture,
}
pub trait EventRetrigger: Component {
type In;
type Out;
fn apply(event_type: In) -> Vec<Out>;
pub enum UiAction {
PlaySound,
SetTexture,
}
pub struct OnHover(Vec<UiAction>);
pub struct OnClick(Vec<UiAction>);
pub struct UiTriggerSystem {
event_reader: Option<ReaderId<UiEvent>>,