GithubHelp home page GithubHelp logo

deft's Introduction

DEFT

Data, Examine, Filter, Task

About

DEFT (Data, Examine, Filter, Task) is the way that I look at all my games made in love, but in a more standarized library.

what?

Things we want to do things with are just data in a table, we look at that table, filter and run tasks based on those filters.

Demo

Simple demo is included that shows the names in a table once and plays a boom about every 1 second.

Functions

Create Deft Class

DEFT = require('DEFT')

This creates the class so you can use DEFT.new() to make unique DEFT boxes.

Conductor = DEFT.new()

Create new Examine Queue

Conductor.examine_new("actor_watch")

Remove new Examine Queue

Conductor.examine_delete("actor_watch")

Run Examine Queue (under update, draw, etc)

function love.update(dt)
  -- Conductor..examine_run(string_name, data, string_sort_method, ...)
  Conductor.examine_run("actor_watch", actors, "standard", dt)
end

You can also call "reverse" instead of standard to walk though the data in reverse order. Good if you're removing values from the table.

Add a Filter to Examine Queue

Conductor.examine_add_filter("actor_watch", "data_has_name")

Conductor.examine_add_filter(string_examine_name, string_filter_name)

Create a new filter

local function data_has_name(data, data_value)
  if data[data_value].name then return true end
end

Conductor.filter_new("data_has_name", data_has_name)

Conductor.filter_new(string_name, function_filter)

Delete a filter (remember to remove it from any Examine queues first)

Conductor.filter_delete(string_name)

Add a task to a filter

Conductor.filter_add_task(string_filter_name, string_task_name)

Create a task

Conductor.task_new(string_name, function_task)

Delete a task

Conductor.task_delete(string_name)

Example

local actors = {
{name = "bob", x=0, y=0, w=16, h=16, state="alive", timer=0},
{name = "sally", x=0, y=0, w=16, h=16, state="alive", timer=0},
{name = "bomb", x=0, y=0, w=16, h=16, state="alive", timer=0, dieon=1},
{type = "point", x=0, y=0},
}

local DEFT_SYSTEM = require('DEFT')

Conductor = DEFT_SYSTEM.new(true)


local function data_has_name(data, data_value)
  if data[data_value].name then return true end
end

local said_names = {}
local function print_names_once(data, data_value, extra_data)
  if not said_names[data[data_value].name] then
    print("Name: ", data[data_value].name)
    said_names[data[data_value].name] = true
  end
end

local function data_has_timer_and_called_bomb(data, data_value)
  local data_part = data[data_value]
  if data_part.timer and data_part.name == "bomb" and data_part.dieon then return true end
end

local function bomb_counts_up(data, data_value, extra_data)
  data[data_value].timer = data[data_value].timer + extra_data[1]
end

local function bomb_blows_up_and_resets(data, data_value, extra_data)
  local data_part = data[data_value]
  if data[data_value].timer > data_part.dieon then
    print("BOOOOOOM")
    data[data_value].timer = 0
  end
end


Conductor.examine_new("actor_watch")
Conductor.filter_new("data_has_name", data_has_name)
Conductor.task_new("print_names", print_names_once)
Conductor.examine_add_filter("actor_watch", "data_has_name")
Conductor.filter_add_task("data_has_name", "print_names")

Conductor.filter_new("data_has_timer_and_called_bomb", data_has_timer_and_called_bomb)
Conductor.examine_add_filter("actor_watch", "data_has_timer_and_called_bomb")
Conductor.task_new("bomb_counts_up", bomb_counts_up)
Conductor.task_new("bomb_blows_up_and_resets", bomb_blows_up_and_resets)

Conductor.filter_add_task("data_has_timer_and_called_bomb", "bomb_counts_up")
Conductor.filter_add_task("data_has_timer_and_called_bomb", "bomb_blows_up_and_resets")


function love.update(dt)
  Conductor.examine_run("actor_watch", actors, "standard", dt)
end

deft's People

Contributors

sysl-dev avatar

Watchers

 avatar

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.