## Polished mixin solution Work has continued with [ARW](https://apps.spelmakare.se/arw) the past weeks. Not much progress with the actual game, been concentrating on reviewing and improving the code before continuing on. I have [previously](https://peakd.com/hive-176981/@smjn/tmos-game-using-mixins-in-typescript) described the Mixin solution, but would like to revisit it as it got some simplifications that are worth talking about. As with the [waitDo class](https://peakd.com/hive-176981/@smjn/arw-game-a-timer-for-making-sequences-of-events), I have [uploaded](https://github.com/smjnab/mixin) the Mixin class to GitHub. <center></center><br> ## Mixin Mixin is a solution based on the alternative solution found on [TypeScriptLang.org](https://www.typescriptlang.org/docs/handbook/mixins.html). I wanted a solution that merged with regular class inheritance and where mixins could be initialized in a similar manner as a regular class. The solution is an abstract Mixin class that is used to create new mixins. Check the [GitHub page](https://github.com/smjnab/mixin) for the code, example and documentation. To keep it short, lets do an example of making a mixin and one example of using that mixin. <br>A basic mixin that adds a string property to a class: ``` export class MixinString extends Mixin { myString: string; MixinString() { this.myString = "MyString"; } MixinStringDestroy() { delete this.myString; } } ``` <br>A class using MixinString to get a string property. The interface is created to get proper type support. ``` // Class using MixinString export class MyClass { constructor(){ Mixin.mixinInits(this, MyClass, MixinString); } destroy(){ this.mixinDestroys(MyClass); } } export interface MyClass extends MixinString { } ``` <br> The above is as basic as you can make it, to the point of making it pointless! To show some actual usage, here is a screenshot from the player class in [ARW](https://apps.spelmakare.se/arw).  **MixinGameObjectBodies** gives a class unlimited rigidbodies and colliders, here it is used to give the player colliders that are used to check various contacts between the player and ground, walls and ceiling. **MixinColliderCollector** gives a class the functionality to collect other objects of interest to do specific events. The objects of interested will be determined by what MixinInteractions they have. If other objects use MixinIntPlayer they will be able to interact with the player. **MixinIntLadder** One of the MixinInteractions that the player have. This gives the player the ability to use ladders. By adding MixinIntLadder to other classes they too can use ladders. As shown here, mixins are very powerful to easily create functionality that can be added to different classes that otherwise have nothing in common or any inheritance. That's it! Thanks for reading. <br> ___ <i> Spelmakare is game development using web technologies. [Spelmakare.se](https://spelmakare.se) [Discord](https://discord.gg/VG5EW9R) [GitHub](https://github.com/smjnab) [Play ARW](https://apps.spelmakare.se/arw) [Play Hive P v. S](https://spelmakare.se/games/hivepvs) </i>
author | smjn | ||||||
---|---|---|---|---|---|---|---|
permlink | arw-game-mixins-for-typescript | ||||||
category | hive-169321 | ||||||
json_metadata | {"app":"peakd/2022.05.9","format":"markdown","tags":["gamedev","development","javascript","smjnblog","gaming"],"users":["smjn"],"image":["https://files.peakd.com/file/peakd-hive/smjn/23swbmk7Zck6on7C2qv34idGmgqXemLWsiVFeqWJghYdgx9bXNRNJF2rmBcDbGD57XqRe.png","https://files.peakd.com/file/peakd-hive/smjn/Eo1vWXrEztM83fvVPtMcA362njd4AdVtkTrYgRRGL8D25MncWMDC9pRazCbAW8k6ztD.png"]} | ||||||
created | 2022-06-10 10:14:39 | ||||||
last_update | 2022-06-10 10:14:39 | ||||||
depth | 0 | ||||||
children | 0 | ||||||
last_payout | 2022-06-17 10:14:39 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 8.030 HBD | ||||||
curator_payout_value | 8.175 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 3,430 | ||||||
author_reputation | 8,662,132,469,561 | ||||||
root_title | "[ARW Game] Mixins for TypeScript" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 113,936,607 | ||||||
net_rshares | 34,946,526,870,732 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
team | 0 | 155,546,998,878 | 20% | ||
mammasitta | 0 | 2,913,659,427 | 1% | ||
roelandp | 0 | 71,670,024,613 | 2.5% | ||
fiveboringgames | 0 | 564,522,869 | 10% | ||
oleg326756 | 0 | 1,188,233,910 | 2.5% | ||
yadamaniart | 0 | 4,261,328,343 | 5% | ||
justinw | 0 | 13,667,850,652 | 3.13% | ||
walterjay | 0 | 35,517,000,078 | 3% | ||
askari | 0 | 11,778,970,646 | 10% | ||
detlev | 0 | 16,305,234,266 | 1.5% | ||
ma1neevent | 0 | 3,580,671,328 | 15% | ||
batman0916 | 0 | 729,293,512 | 4.75% | ||
rt395 | 0 | 2,249,930,085 | 2.5% | ||
rawselectmusic | 0 | 1,995,263,312 | 5% | ||
jayna | 0 | 10,751,667,139 | 2% | ||
guchtere | 0 | 940,644,162 | 4.75% | ||
tipy | 0 | 8,943,586,672 | 100% | ||
diegoameerali | 0 | 863,617,308 | 3% | ||
dante31 | 0 | 626,373,390 | 5% | ||
howo | 0 | 282,799,709,930 | 10% | ||
ocd | 0 | 1,570,098,442,457 | 10% | ||
macchiata | 0 | 333,239,527,253 | 50% | ||
joshruiz | 0 | 2,611,134,773 | 9.5% | ||
kimzwarch | 0 | 14,758,972,535 | 4% | ||
jlsplatts | 0 | 20,455,640,187 | 2% | ||
kevinbacon | 0 | 867,204,797 | 100% | ||
hanggggbeeee | 0 | 879,700,726 | 5% | ||
eonwarped | 0 | 75,404,502,521 | 3% | ||
felipejoys | 0 | 82,606,358,788 | 100% | ||
itchyfeetdonica | 0 | 118,252,523,907 | 20% | ||
spiritabsolute | 0 | 35,686,304,239 | 100% | ||
tomatom | 0 | 846,021,843 | 5% | ||
anikekirsten | 0 | 513,408,627 | 5% | ||
gabrielatravels | 0 | 1,840,467,396 | 4% | ||
emjoe | 0 | 13,833,621,473 | 100% | ||
ricardo993 | 0 | 1,452,646,018 | 6% | ||
mproxima | 0 | 56,171,757,024 | 100% | ||
ocd-witness | 0 | 15,915,814,277 | 10% | ||
scooter1010 | 0 | 772,402,121 | 50% | ||
miroslavrc | 0 | 2,696,032,326 | 5% | ||
sanderjansenart | 0 | 15,971,033,630 | 10% | ||
obsesija | 0 | 1,981,819,855 | 4.75% | ||
wirago | 0 | 103,330,574,808 | 100% | ||
lologom | 0 | 6,955,403,390 | 100% | ||
indigoocean | 0 | 2,315,739,674 | 5% | ||
veteranforcrypto | 0 | 1,301,199,373 | 3% | ||
nateaguila | 0 | 180,239,756,068 | 5% | ||
corinadiaz | 0 | 467,094,881 | 5% | ||
haccolong | 0 | 3,399,649,763 | 5% | ||
nathyortiz | 0 | 2,170,532,929 | 5% | ||
steemulant | 0 | 411,857,616 | 20.01% | ||
olumzy | 0 | 448,567,623 | 3% | ||
ocdb | 0 | 30,225,776,564,464 | 9.5% | ||
mastersa | 0 | 3,096,433,900 | 60% | ||
lifeskills-tv | 0 | 4,960,332,938 | 4.75% | ||
hoaithu | 0 | 1,229,281,212 | 4.25% | ||
anhvu | 0 | 877,683,030 | 4% | ||
pradeepdee6 | 0 | 4,505,568,001 | 4% | ||
javyeslava.photo | 0 | 1,769,836,899 | 4.5% | ||
voter003 | 0 | 8,125,920,774 | 3.6% | ||
tsunsica | 0 | 1,214,532,506 | 10% | ||
multifacetas | 0 | 504,203,645 | 5% | ||
devann | 0 | 15,569,409,208 | 4% | ||
variedades | 0 | 1,350,058,989 | 3.8% | ||
cryptofiloz | 0 | 16,504,966,224 | 9.5% | ||
squareonefarms | 0 | 1,035,413,877 | 5% | ||
alexkopareiko | 0 | 0 | 100% | ||
yiobri | 0 | 1,168,489,466 | 5% | ||
poliwalt10 | 0 | 1,261,221,115 | 2.37% | ||
beerlover | 0 | 1,901,524,679 | 1.5% | ||
ph1102 | 0 | 82,870,030,026 | 9.5% | ||
obelus | 0 | 2,513,143,100 | 50% | ||
zeesh | 0 | 2,142,142,796 | 5% | ||
oblivioncubed | 0 | 377,676,834,549 | 100% | ||
lacking | 0 | 291,565,749,853 | 100% | ||
bilpcoinbpc | 0 | 895,678,136 | 6.97% | ||
dpend.active | 0 | 709,235,614 | 2% | ||
actioncats | 0 | 11,608,876,277 | 9% | ||
gabolegends | 0 | 895,208,570 | 2.5% | ||
olaunlimited | 0 | 6,971,896,706 | 4% | ||
kawsar8035 | 0 | 2,528,382,973 | 2.85% | ||
chubb149 | 0 | 489,206,347 | 2% | ||
meritocracy | 0 | 525,163,686,379 | 4.75% | ||
dcrops | 0 | 29,984,306,709 | 4.75% | ||
mundo.curioso | 0 | 212,577,377 | 100% | ||
cielitorojo | 0 | 8,329,012,503 | 6.65% | ||
elgatoshawua | 0 | 2,194,739,113 | 4.75% | ||
hexagono6 | 0 | 568,048,090 | 4.75% | ||
leveluplifestyle | 0 | 2,192,518,466 | 5% | ||
chimp.ceo | 0 | 500,658,381 | 7.5% | ||
brujita18 | 0 | 1,074,674,662 | 5% | ||
partiesjohall | 0 | 1,755,505,004 | 10% | ||
aprasad2325 | 0 | 1,720,616,461 | 4.75% | ||
ivycrafts | 0 | 1,173,570,713 | 5% | ||
violentbird | 0 | 500,788,924 | 50% | ||
wendy0520 | 0 | 754,974,183 | 10% | ||
imoogin3v3rm0r3 | 0 | 757,369,012 | 30% | ||
tristan.todd | 0 | 2,089,935,957 | 10% | ||
str33tl1f3 | 0 | 665,180,890 | 10% | ||
killerwot | 0 | 512,120,831 | 5% | ||
xocdb | 0 | -131,532,215 | -9.5% |