Sunday, October 12, 2014

Alpha Build

I just got my personal framework to Alpha build.  It works... mostly but there is not much to it.

The main focus of it is to make fast and easy web applications that scale.  It will be the base framework for my web games. If your into web applications and want to check out a cool Common JS framework, I am offering the Alpha Build free on my site.www.fracturednations.com

If you want to see it working, its not much, but it works.  Here are two demo sites that I am putting together.

www.fracturednations.info
system.fracturednations.info

Joseph Tveter
www.fracturednations.com


Wednesday, July 30, 2014

Geolocation woes

Apparently HTML5 has an api to get me exactly where I am on the planet.  But it can't tell me what country I am in.  Google will tell me. Google knows all.

    this.getGeoLocation = function()
    {
        var deferred = $.Deferred();
        if(navigator.geolocation)
        {
            navigator.geolocation.getCurrentPosition(function(position)
            {
                deferred.resolve(position);
                //position: {"coords":{"speed":null,"accuracy":65,"altitudeAccuracy":10,"altitude":1410.8349609375,"longitude":-111.72789187811416,"heading":null,"latitude":40.332329714635044},"timestamp":1406740874211}
            });
        }
        else
        {
            deferred.reject({error: "FAIL"});
        }
     return deferred.promise();
    };

Wednesday, July 2, 2014

Wait for it....

Deferred Objects with jquery.  Great for when you are waiting for data to process or servers to reply.

var deferredData = $.Deferred();
deferredData.done(function(result)
{
     //do stuff
}).fail(function(errorObj)
{
     //handel error
}).always(function(result)
{
     //whatever is returned comes here as well.
});

// when the data is done simply call
deferredData.resolve(result);

//or if you want to fail
deferredData.reject(errorObj);

Tuesday, January 7, 2014

Web page scaling to the device!

Web page scaling to the device! Even with different pixel ratios! Will work with android, iPhone and web!

var dpi = window.devicePixelRatio || 1;
var width = $(window).width();
var ratio = 52; //Ratio of target font size to screen width screenWidth/idealFontSize
var font = Math.ceil((width / dpi / ratio)+dpi*3);
if(font < 15)
    font = 15;
// any less is not useable.

$("html").css({"fontSize": font});

Enjoy!

Saturday, November 9, 2013

Cookie Module and Common JS

With the slow death of flash I have decided to build my game on a javascript MVC framework. The core is using the Common JS library Inject.

This mornings project was creating a cookie manager.  I stole and modified some basic cookie functions from W3Schools, and put it into the Common JS structure.  Happy Scripting.

Here is the code to call it.
////////////////////////////////////////////////////
var Cookie = require("modules.model.Cookie");

var App = function()
{
  this.Cookie = new Cookie();

  //set the cookie
  this.Cookie.setCookie("UserName", "Bob");

  //Get the cookie
  var userName = this.Cookie.getCookie("UserName");
  alert("Username = " + userName);

  //is the cookie
  var isUser = this.Cookie.isCookieValue("UserName", "Bob");
  alert("Is Bob the User? " + isUser);
};
///////////////////////////////////////////////////

Here is the module
/////////////////////////////////////////////////
var Cookie = function()
{
var self = this;
this.DEFAULT_EXP = 30; //days

this.setCookie = function(c_name,value,exdays)
{
var exdate=new Date();
if(!exdays)
{
exdays = self.DEFAULT_EXP;
}
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
};

this.getCookie = function(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
 {
  c_start = c_value.indexOf(c_name + "=");
 }
if (c_start == -1)
 {
  c_value = null;
 }
else
{
 c_start = c_value.indexOf("=", c_start) + 1;
 var c_end = c_value.indexOf(";", c_start);
 if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
};

this.isCookieValue = function(name, value)
{
debugger;
var cookie = self.getCookie(name);
 if(cookie===null || cookie==="")
 {
  return false;
 }
else
 {
  if(cookie === value)
   {
    return true;
   }
   else
   {
    return false;
   }
 }
};
};

module.exports = Cookie;
///////////////////////////////////////////////

Saturday, August 17, 2013

Singleton vrs Dependency Injection.

I have been starting to nail down the framework for my game. I have been reviewing my php knowledge base, on how to solve global variable, and object issues. I have friends that have been using singleton classes, and I defiantly see where they are going with it. It is handy for making sure you only have one instance of the thing running around, especially if you are dealing with a single object such as a web user. But I just don't feel it is the right solution for me. I think I am going to go more toward dependency injection at the bootstrap. My controller structure extends each other based on the page. So the sub page of a sub page will have been extended with each page all the way back to the main site controller. And any additional needed dependencies can be loaded for a new sub page controller. I can see going singleton if you have more then 1 controller object, which I have seen that approach before but it seemed cumbersome. I don't like cumbersome. I think it will be one controller that has been extended from the root, with dependency injection. Seems like it would be cleaner.

Saturday, July 20, 2013

Web Programmer, Tech Levels

Web Programmer, Tech Levels

What do you mean by Senior Web Programmer? After spending several years in the web development field, I think there needs to be a clarification on what a Senior Web Programmer is.  I have met people who's scripting ability is nothing less then beyond mortal.  And I have met some "Senior Programmers" who have code so dirty that it might be likened to a mud pit.  So I present to the general population of the world and, anyone else who might care a better scale to rate people on then Jr, and Sr, programmers.

Wanaabe

Yes I have built a website and it was legit.  I used a website builder and even went in to the code and added a <br>

Neophyte

I took some classes/read some books and learned html.  I use Dreamwaever, Druple, and Wordpress.

Web Guy

I build tons of web pages, I still might use Dreamweaver, Druple, or Wordpress. I have been working with libraries and frameworks.

Grunt

I have written some extensions for some frameworks and have started building up my own libraries

Minion (right hand man/women/igor)

I have extensive libraries, and am building my own framework.

Overlord

I have my own framework, and it has been used on several projects.

Neo

I don't believe in frameworks I just believe in me. Coo Coo Ka Choo.


And those looking to hire me I fall in to the Grunt catigory, and am on my way to Minion