├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── buildpackage.bat ├── haxelib.json └── ice ├── entity ├── Component.hx ├── Entity.hx ├── EntityManager.hx └── IceUtil.hx ├── fsm └── FSM.hx ├── group └── EntityGroup.hx ├── parser ├── IceInterp.hx ├── Script.hx ├── ScriptHandler.hx └── ScriptHolder.hx └── wrappers ├── FlxCameraFollowStyleWrap.hx ├── FlxColorWrap.hx └── FlxKeyWrap.hx /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !ice/ 4 | !ice/* 5 | !ice/entity/* 6 | !ice/parser/* 7 | !ice/fsm/* 8 | !ice/wrappers/* 9 | !ice/group/* 10 | !haxelib.json 11 | !CHANGELOG.md 12 | !LICENSE.md 13 | !README.md 14 | !buildpackage.bat -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 1.3.0 2 | ------------------------------ 3 | * many, many bugfixes and safety checks 4 | * `switchState()` added 5 | * `` element added 6 | * `FlxKeyWrap` Added 7 | * `FlxColorWrap` Added 8 | * `newObject()` Added for scripts 9 | * create instances of template from code instead of XML 10 | * fix freezing on wrong asset path 11 | * `EntityGroup` added (just `FlxTypedGroup`) 12 | * fix depth ordering for XML files 13 | * `prefab` element added 14 | 15 | 1.2.0 16 | ------------------------------ 17 | * added an api for accesing variables on scripts, while retaining type-safety 18 | 19 | 1.1.1 20 | ------------------------------ 21 | * fixed multiple destroy() functions, so state switching, etc. work properly 22 | 23 | 1.1.0 24 | ------------------------------ 25 | * allow use of % in entity declarations, referring to game width or height 26 | 27 | 1.0.2 28 | ------------------------------ 29 | * allow animation addition using entity.loadAnimation() (lets you use fancy frame declarations) 30 | 31 | 1.0.1 32 | ------------------------------ 33 | * allow adding scripts to an entity via entity.scripts.ParseScript(path) 34 | * fix new entities in groups not being drawn 35 | * allow type declarations in callable functions 36 | 37 | 1.0.0 38 | ------------------------------ 39 | * rewrite scripting system, allow for real haxe files 40 | * remove map property on EntityManager 41 | * add instance and template creation for entity xml files 42 | 43 | 0.10.1 44 | ------------------------------ 45 | * extend interp to allow property access on objects 46 | 47 | 0.10.0 48 | ------------------------------ 49 | * add syntax for exposing and requesting classes inside of scripts 50 | 51 | 0.9.0 52 | ------------------------------ 53 | * add simple fsm system 54 | 55 | 0.8.2 56 | ------------------------------ 57 | * fix parsing mistake causing scripts to only load if the entity had an art element 58 | 59 | 0.8.1 60 | ------------------------------ 61 | * make sure to check that entities aren't null 62 | 63 | 0.8.0 64 | ------------------------------ 65 | * add noreload option 66 | * make scripts delete if they only have init logic (unless noclean is specified) 67 | 68 | 0.7.0 69 | ------------------------------ 70 | * allow access to instance via a property 71 | 72 | 0.6.3 73 | ------------------------------ 74 | * fix backward conditionals that broke string loading 75 | 76 | 0.6.2 77 | ------------------------------ 78 | * only call @reload if script changed 79 | 80 | 0.6.1 81 | ------------------------------ 82 | * add option for true live-reloading 83 | 84 | 0.6.0 85 | ------------------------------ 86 | * integrate live-reloading of external scripts 87 | * add @reload function for scripts 88 | * change Owner to GID 89 | 90 | 0.5.6 91 | ------------------------------ 92 | * fix spelling of receive 93 | 94 | 0.5.5 95 | ------------------------------ 96 | * check destroyScript for null 97 | 98 | 0.5.4 99 | ------------------------------ 100 | * fix underlying mistake that caused the need for the if(!init) check 101 | 102 | 0.5.3 103 | ------------------------------ 104 | * hard-code the if(!init) check 105 | 106 | 0.5.2 107 | ------------------------------ 108 | * fix parsing of entity scripts 109 | 110 | 0.5.1 111 | ------------------------------ 112 | * fix for new handling of flxgroups 113 | * add init variable to (sort of) fix recurring init 114 | 115 | 0.5.0 116 | ------------------------------ 117 | * added hscript integration 118 | 119 | 0.4.0 120 | ------------------------------ 121 | * changed group storage and behaviour 122 | * split AddEntity() into separate methods 123 | 124 | 0.3.1 125 | ------------------------------ 126 | * added ability to use hyphens in animation parsing 127 | 128 | 0.3.0 129 | ------------------------------ 130 | * added entity xml parser 131 | 132 | 0.2.1 133 | ------------------------------ 134 | * added destruction of entities 135 | * removed template 136 | * added haxelib setup 137 | 138 | 0.2.0 139 | ------------------------------ 140 | * marked version numbers (not coded anywhere in project, just for reference) 141 | * all classes have replaced the word "gameobject" with entity, I know its annoying, but in the end its shorter to type... 142 | * added a simple message broadcasting system 143 | * added distance measuring between entities 144 | * added IsAgainst() for determining if an entity is directly touching something in a given direction 145 | 146 | 0.1.1 147 | ------------------------------ 148 | * packages have been renamed to: ice.entity.[class]. 149 | * code has been surrounded in a template haxeflixel project, with EntityManager already added. 150 | 151 | 0.1.0 152 | ------------------------------ 153 | * code ported from IceEntity 154 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Nico May 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | IceEntity 2 | ========= 3 | 4 | ![IceEntity Demo](http://i.imgur.com/9tQt9rh.png) 5 | 6 | A simple framework for managing entities and components in HaxeFlixel 7 | 8 | **[ATTENTION ANY/ALL USERS]** Please move to the development branch (relies on dev flixel), as I can no longer guarantee updates to anything else, sorry. 9 | 10 | **[NEW] [sample project here](https://github.com/NicoM1/IceEntity-Sample) [NEW]** 11 | 12 | (The above may be a much simpler way to learn much of what is included in this readme, as well as some smaller, but still useful features) 13 | 14 | **Changes:** 15 | ---------- 16 | 17 | **[NEW v1.2.0]** 18 | 19 | Added an api for accesing variables on scripts, while retaining type-safety (`Entity.getVar()`) 20 | 21 | **[NEW v1.1.0]** 22 | 23 | Allow use of % in entity declarations, referring to game width or height 24 | 25 | **[NEW v1.0.0]** 26 | 27 | Rewrote entire scripting system, allowing proper Haxe classes to be parsed as scripts 28 | 29 | Added templates and instance creation to XML parser 30 | 31 | **[v0.10.0]** 32 | 33 | Added syntax for exposing and requesting classes inside of scripts 34 | 35 | **[v0.9.0]** 36 | 37 | Added simple FSM system (sorry no write-up yet) 38 | 39 | **[v0.8.0]** 40 | 41 | Added "noreload" option for script elements 42 | 43 | Made scripts remove after calling init, unless they have update or destroy logic 44 | 45 | **[v0.7.0]** 46 | Allow access to instance via a property 47 | 48 | **[v0.6.1]** 49 | Made live-reloading fully automatic 50 | 51 | **[v0.6.0]** 52 | Added live-reloading of scripts 53 | 54 | **[v0.5.0]** 55 | Added hscript integration 56 | 57 | **Earlier:** 58 | 59 | [See Changelog](https://github.com/NicoM1/IceEntity/blob/dev/CHANGELOG.md) 60 | 61 | **Installation** 62 | ---------- 63 | 64 | **[1]** Run ```haxelib git iceentity https://github.com/NicoM1/IceEntity dev``` in a terminal with access to git 65 | 66 | **[2]** Add `````` to your ```Project.xml``` file, directly under `````` 67 | 68 | **[3]** MAKE COOL THINGS:D 69 | 70 | 71 | **Usage:** 72 | ---------- 73 | 74 | Call ```add(EntityManager.instance);``` in the create function of your playstate. 75 | 76 | Use ```EntityManager.instance.AddEntity();``` to add objects or groups to the manager. 77 | 78 | Use ```AddComponent();``` on a class extending entity to add a new component. 79 | 80 | ```init()``` will run on the first update cycle, useful for getting and stashing references to other entities. 81 | 82 | **Entity Parser:** 83 | ---------- 84 | IceEntity includes an xml parser, which can build entities from simple xml files. In order to use this system, you must: 85 | 86 | **[1]** Create an xml file with this structure: 87 | 88 | 89 | 90 | //"%" is new as of V1.1.0, it allows you to specify a percentage of game width or height, instead of an exact value 91 | 92 | 93 | //ANIMATIONS: all parameters must be supplied, except "autorun" which mearly starts the animation as soon as it is loaded 94 | //FRAMES: as of v0.3.1, "frames" can now use hyphens, allowing you to do things such as: "0-10", or "10-0", note that commas are still allowed, and this is valid: "0-10,10-0,0,1,2,3,4,5,6,7,8,9,10" 95 | 96 | 97 | 98 | 99 | //CHECK NEXT SECTION FOR SCRIPTING INFORMATION (yes, you can write code here!!) 100 | 101 | 102 | [NEW as of 1.0.0] 103 | /*This is a "template" it can be used to create many instances of a premade entity, 104 | simply declare the entity as usual, and add an identifier: template="identifier". 105 | Note that by default, entities with a template attribute are not built at startup, 106 | however you can do so by adding instance="true" to the declaration. 107 | Note this is a single line for clarity, but this "template" would in practice look 108 | the same as the above entity declaration, with art and all*/ 109 | 110 | 111 | /*This is an "instance", you can instantiate a template as many times as you wish, 112 | while altering tag and position.*/ 113 | 114 | 115 | 116 | **Important information:** 117 | 118 | Parameters for components **must** be in the same order as specified in their constructor, **passing the entity's GID is not required**, it will be auto set. 119 | 120 | Param "name" attributes are not required, but are strongly recommended for organization. 121 | 122 | Allowed types for parameters are: **"int" "float" and "bool" anything else will be treated as a plain string, including a lack of the "type" attribute**. Capitalization on param types does not matter. 123 | 124 | **MOST IMPORTANTLY: any component you wish to add in a xml file MUST be referenced somewhere in your basecode, even adding an ```import com.me.MyComponent;``` to your playstate will work. xml parsing will not work without this, as the component will not be compiled.** 125 | 126 | **[2]** Call ```EntityManager.instance.BuildFromXML("assets/data/MyEntities.xml");``` in your playstates create function (or wherever really). 127 | 128 | **HScript Integration:** 129 | ---------- 130 | 131 | As of v1.0.0, IceEntity's scripting system has been completely rewritten, with work from both me and @Ohmnivore, making the act of scripting at runtime much more user friendly. Note this is a new feature, relatively untested, and may not be as efficient as standard components. If you find an issue, or are confused, tweet to me at: [@nico_m__](https://twitter.com/nico_m__), or email me: nico(dot)may99(at)gmail(dot)com. **These features allow you, the developer, to program your game in standard Haxe code, without recompiling, at runtime.** I'll let you think of the possibilities:). It also means, that with little or no work, modding can be integrated into your game! Here are the steps to getting this to work in you game: 132 | 133 | **[1]** In you entity xml file (described above), there are two places you can put scripts. One being inside of an entity declaration, like so: 134 | 135 | 136 | 137 | 138 | 186 | 187 | As you can see, the "expose" tag allows the script to gain access to a static class, and reference it as whatever is in the "name" attribute. The "request" tag allows the script to get access to a class instance (or, truthfully, a static class will also work), from the ```ScriptHandler```s global pool. You can add to the pool in your code with ```ScriptHandler.AddModule(name, value);``` Note that this must be done BEFORE you parse the entity file, or you will get a nasty error message. 188 | 189 | **[3]** You may be (rightly) thinking: **"Hey, you said we were using real Haxe, that doesn't look like real Haxe to me?"** The reason for this: IceEntity's parser has been written to be flexible with how you want to write your scripts, if all you need is a few lines doing something really simple, the above is easier to type, **however**, if you wish to get full IDE support **(auto-completion)**, you can program your scripts like this (or pretty much anywhere in-between the two styles): 190 | 191 | package ; 192 | 193 | import flixel.FlxG; 194 | import ice.entity.Entity; 195 | 196 | class Test 197 | { 198 | //# 199 | var owner:Entity; 200 | /* 201 | This is a special syntax used in scripts. 202 | It allows you to create variables that are not compiled when the script is parsed. 203 | Why? 204 | This way, if you have used a request tag, or wish to have completion for the scripts owner, 205 | you can create a variable of the proper type, 206 | allowing full completion, without fearing issues in your scripts 207 | You may only use one of these blocks per script, simply open with "//#" and repeat to close. 208 | */ 209 | //# 210 | public static var testEntity = new Entity("myTag"); /* 211 | These variable are live-reloaded only if they 212 | did not previously exist, changing a value will not 213 | reload the variable, however if you add a new 214 | variable, it will be detected. 215 | */ 216 | 217 | public function init() 218 | { 219 | var p:Entity = new Entity(); 220 | } 221 | 222 | public function update() 223 | { 224 | test("hello world"); 225 | } 226 | 227 | public function reload() 228 | { 229 | 230 | } 231 | 232 | //@ 233 | function test(t) 234 | { 235 | trace(t); 236 | } 237 | /* 238 | This is another special syntax, any function placed inside of this block (one per script), 239 | acts how you would expect a standard haxe function to act, and is live-reloaded. 240 | */ 241 | //@ 242 | } 243 | 244 | **[4]** The scripting system relies on hscript, which is basically interpreted Haxe. Unfortunately, I do not know enough about hscript yet to explain everything you can and can't do, but an important item to note is to not use properties in scripts, you must instead just use methods (as far as I can tell...). If you are more experienced in hscript, please submit a pull request with a fuller description:) 245 | 246 | **[5]** As a developer, you may not want scripts, specificity mods, to have access to sensitive areas of your game. There are two ways to achieve this. The broad stroke way is to completely disallow access to the expose tag, ensuring scripts have no access to anything unless you specificity add it to the ```ScriptHandler```s modules list. This can be done with: ```ScriptHandler.allowExpose = false;```. The second, more specific way is to "blacklist" classes with ```ScriptHandler.Blacklist("path.to.Class");```, this will warn the user they can not access this package. 247 | 248 | **Note: this section has been converted for the changes in IceEntity's scripting system, however, it is possible some items are incorrect, if something isn't working how it says, or how you feel it should, please let me know [@nico_m__](https://twitter.com/nico_m__) ,thanks:D** 249 | 250 | **Live Scripting** 251 | ---------- 252 | 253 | ![Live-Scripting Demo](http://i.imgur.com/CkyiKeF.gif) 254 | IceEntity allows you, with minimal effort, to literally code your game **while it is running**. This currently only works for CPP and Neko builds, and only for external script files (ie scripts created inside of your entities.xml file will not be editable at runtime). Here is what you need to do to make use of this new feature: 255 | 256 | **[1]** Any scripts you want to be able to edit at runtime must be taken out of your xml file, placed in their own file, and then declared in your script element's "path" attribute. 257 | 258 | **[2]** You can now import and request classes inside your scripts, similar to how imports are handled in regular haxe: 259 | 260 | import flixel.FlxG; //this is identical to the expose tag in xml, except you do not control the name of the class, the last section is used, in this case: "FlxG". 261 | request MyClass; //this is identical using a request tag in your xml 262 | 263 | function init 264 | { 265 | 266 | } 267 | 268 | This also means the live-reloader will update your imports, so you can add things as you need them. This, however, may slow the reloader, if you find that to be the case, you can add: 269 | 270 | 271 | 272 | to your project.xml file. 273 | 274 | **[3]** To help with testing, a new scripting function has been added: 275 | 276 | function reload 277 | { 278 | //This runs every time the script is updated, you can use it to edit variables for testing. 279 | //Note that it is ONLY for testing, you should not use this for any real game code, just for playing with values for speed and so on. THIS NEVER RUNS IN A FINAL BUILD 280 | } 281 | 282 | **[4]** The files you edit while making use of live reloading **are not your main files**. The files you want to edit are in: yourProject\export\windows\ (neko or cpp)\bin\assets\data. **If you wish to use the logic you've created, copy these files back into your main folder when you are done**. 283 | 284 | **[5]** Reloading can be costly; you may not wish to reload every script when you only want to tweak a couple. To stop certain scripts from reloading, a "noreload" attribute has been added for script elements: 285 | 286 |