First of all, the question should be a bit bigger but that is the main point, I guess.
Let me explain a little of what I want to do so you can have a better idea. Basically, id like to make a card game (no 3D nor 2D graphics), just a basic form where I have a deck of cards loaded in memory. After playing a card i'd like the form to update some information (labels, images, or X behavior) based on the card's effect, however, I don't want to hard code the card interactions/effects within the card control, I want to get all that from a script (for example a lua script). For example:
I have a script named "0001.lua" and it has 2 effects coded;
Deal 2 damage to opponent.
Deal 4 damage to opponent and destroy this card.
In the game I draw a card with ID 0001 and play it. When right clicking the control that works as a card, id like to display a list the effects in the script and depending on the chosen option to execute the selected function inside the script and update the information in the form (if it was effect 2 - deal 4 damage and destroying the control/card).
with all this in mind id like to ask the following questions:
How can i achieve something like that?
Is that called "embedding"?
In the information I mentioned lua as the scripting language but I don't know if that is the simplest scripting language i can use to do this, is there a simpler scripting language? I would like to keep it as simple as possible.
Can anyone provide an example to do something like this? I'll greatly appreciate it (it's okay if it's simple, I just want to know how to accomplish the back and forth communication between the script and c#)
Also, c# is no a requisite. I just mentioned c# because I feel comfortable coding in it. If there is another language more appropriate for this task i'm open to suggestions.
I think that it is much more simple to use C# scripts from C# than lua.
Check out these questions
[1],
[2].
Note: Don't forget about namespaces. If you want your scripts classes to inherit your classes or interfaces from main application, then your scripts should use same namespace.
Related
I have questions about the best way to implement something. This involves CSS, HTML and Javascript.
My intent is to write something like a list of preferences (How much you like drama from 1-5, romance from 1-5, action 1-5) that's editable client-side, shareable client-side, and comparable client-side (add "thriller"; show off your ratings; compare someone else's ratings with yours). I'd ideally like all of this to take place on a single page.
My interpretation of how to handle the list itself has been through radio buttons and labels. Right now it looks like this:
My interpretation of how to do the self-editable part is to have a text field on the page with a button that updates the page based on the text inside the field.
However, before I get too deep I want to make sure I'm not approaching this all wrong, and I'd appreciate input on how to do the next bits. Specifically: how should I implement sharing and comparing lists? My instinct was to follow through on my forms but anything with GET will lead to one mess of a url and anything with POST, as far as I know, won't be accessible in the way I want it.
If you can shed some light on this problem, I'd be very grateful!
I'm writing a boardgame hub as a personal project, to learn/discover more about AngularJS.
I tried to go for a generic implementation, so I have a generic partial that shows a square grid and a generic controller, with all actual game logic residing in a service. I've written one such service for each boardgame I've implemented (currently 2). The one thing I can't solve in a generic manner is a cell in the grid. Depending on the game, its content may be a letter, a number, a picture, or even some (quite complex) HTML.
I could use a getter function, that would call the service, that would assemble the HTML for each cell, but this feels really not-Angular-ish.
So I thought of defining a directive for each type of cell. How do I place a directive conditionally in the page (based on the game type, decided in the controller)?
If you can come up with a more elegant solution, which does not require this hack-ish thing, I'd be glad to hear it.
I think I have a pretty good solution for this. Build an HTML mockup of the UIs for each of the two games you have at the moment. Put together the cells, styles, images, etc. They don't have to be perfect but they should approximate how you see them being built.
Now try to unify the HTML of them so they are as similar as possible underneath the covers and that commonality should suggest to you what the pieces you need for the front end. For example, lets say you've done a really boring old game like Chess (rather than something interesting like King of Tokyo or Carcassonne :) and you see that you've got individual squares that work nicely as divs.
<table>
<tr ng-repeat="row in board">
<td ng-repeat="square in row">
<div ng-class="square.class()"><img ng-src="square.img()"/></div>
</td>
</tr>
</table>
Each square supplies both a class for its styling and a transparent PNG file that can be displayed there to show the different chess pieces on the squares. It's an idea. But it may fail completely for your game because it lacks the interaction you need or animation or something else that's critical for the user experience you're trying to create.
Ultimately you have to work backwards from the UI and not forward from what you think the API should look like. I'll quote Tom Dale talking about Ember Data, "We committed the cardinal sin of inventing an API rather than extracting it..."
I'm not sure if javascript is the best solution but here's what i want to achieve.
The web page is divided in 3 columns...
The left column should have links in picture format like Arts, History, Science etc
Clicking on any of these link should generate a series of links in the rightmost column say clicking on history should generate links for Civilization, World war etc Science should generate links like Physics chemistry represented by pictures etc and so on
Finally Clicking on these links say World war should display the content in the central column giving a brief history on World war....
Also each time a user clicks on an image link say Science it should get highlighted so the user can navigate easily from one topic to another.
I'm a novice to programming, not sure if javascript is the best approach. Also I'm very confused as to how to go about this problem where to begin and how. Any help in terms of code chunks or references or algorithms or advice on how to approach this problem would be most appreciated. If solving this problem means learning a new programming language i'm open to try.....
In case if i'm not clear in explaining the problem let me know
JavaScript would be appropriate for this. The appropriate approach will depend on how much content you have.
If it's reasonably short, you can achieve all of this by simply changing the display property on your elements (use JavaScript to set the CSS of certain page elements to show (display:block) or to hide (display:none).
If you have pages of text, you may want to look into Ajax. It is a bit more advanced that simply showing and hiding elements that are already there.
I am pretty sure that I know the answer to this already, but I am interested to see if anyone has other ideas. We are working on a website to include a major redesign with mega menus. One of my top things in a redesign is to reduce the page download time as much as is possible. All my images, css and javascript are cached and that's good. However, the part that I am trying to work through is the html coding for the menu, and if there is a way to locally cache that within reason.
As a side note, I like to do things as pure CSS as possible (for SEO), and so that would include outputting the mega menus directly onto the HTML page. But at the same time, I know that if it takes a number of seconds for the page to download the html content at the top, well, then, we are probably going to be running some customers off there too. Maybe the best then would be to have JavaScript output the menus, but then you run into the couple of customers that don't have Javascript enabled.
Right now the pages are about 30K for the menus, and I anticipate that doubling and maybe more when we do the redesign.
Do you have some thoughts for this issue? What would you see as the best way to tackle this?
Thank you!!
JMax
Honestly, 30K for an element is nothing in this day and age, with high-speed connections common and browsers effectively caching as necessary. People don't leave because of a second or two. It's when you have Flash movies that preload or crazy auto-starting videos that people get annoyed in a hurry.
I've got a similar application with a menu that's likely double that right now...let me add, it's not by choice, it's something I inherited and have to maintain for the time being. The menu is output simply in an unordered list and then I use Superfish and CSS to do the styling as necessary. There's an initial hit, but after that, caching kicks in and we're good to go. Even as crazy as it is, the load isn't prohibitive. Navigating it, however, is a mess. I'd strongly recommend against confusing the heck out of your user with so many choices, especially on a mega menu that can be a UI hurdle for disabled and older users. When you boil it down, the whole basis behind the "Web 2.0 movement" (I hate that term) is to minimize or cloak complexity.
If you're REALLY concerned about performance, start off with what you're loading. Limit your Javascript by combining files, especially those small Jquery files that tend to stack up. HTTP requests can severely impact a site, especially since they monopolize the loads initially. Similarly, combine small CSS files and optimize the rest via an online tool To reduce image loads, create sprites for your graphics so you're loading one file instead of many. Here's a tut on Sprites and a simple google search will give you dozens of sites that will build the sprite and css automatically. Load anything you can from CDN, such as Jquery, Prototype, etc (hopefully only one framework per site, because two or more is unnecessary)
If you're still out of hand, look at your graphics one more time. Could you take advantage of pure CSS or image repeating via CSS to reduce loads further? Have you optimized all the graphics? Could you tweak the design to take advantage of those tricks?
After all that, if you simply can't change the menu to be more friendly, start investigating options. However, I suspect you'll find better gains in the first couple of steps than you would from taking extreme measures on the menu.
You could either set HTTP caching for a javascript code file that generates the menu, or use ajax to insert a pre-generated HTML menu from another file (again with a long expiry date set on cache).
Both those solutions require javascript through. I can't think of another way to remove the menus from the HTTP traffic apart from an IFRAME (yuck).
30k is massive for plain HTML though - do you REALLY need such a huge navigation structure?
I have been using nagios + pnp4nagios for a while and am happy with the images rrdtool creates. My current task is to create a panel that has some statistics generated by nagios and after a while the statistics change. I'm looking for something like that:
But also able to switch screens automatically. I do know that I can make a timed javascript function that switches the layout after a determined time, but I also want to add effects and other stuff to the picture. Any good javascript library that has it?
such effects can be achieved easily with most javascript libraries. I like jQuery quite well. See the examples in link text for inspiration